Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the copy/paste logic in the integration tests and fix a race condition involving the waitForEvent integration test helper function #18331

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions test/integration/copy_paste_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@

import {
closePages,
kbCopy,
copy,
kbSelectAll,
loadAndWait,
mockClipboard,
waitForEvent,
} from "./test_utils.mjs";

const selectAll = async page => {
const promise = waitForEvent(page, "selectionchange");
await kbSelectAll(page);
await promise;
await waitForEvent({
page,
eventName: "selectionchange",
action: () => kbSelectAll(page),
});

await page.waitForFunction(() => {
const selection = document.getSelection();
Expand Down Expand Up @@ -55,10 +57,7 @@ describe("Copy and paste", () => {
);
await selectAll(page);

const promise = waitForEvent(page, "copy");
await kbCopy(page);
await promise;

await copy(page);
await page.waitForFunction(
`document.querySelector('#viewerContainer').style.cursor !== "wait"`
);
Expand Down Expand Up @@ -159,10 +158,7 @@ describe("Copy and paste", () => {
);
await selectAll(page);

const promise = waitForEvent(page, "copy");
await kbCopy(page);
await promise;

await copy(page);
await page.waitForFunction(
`document.querySelector('#viewerContainer').style.cursor !== "wait"`
);
Expand Down
98 changes: 37 additions & 61 deletions test/integration/freetext_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import {
awaitPromise,
closePages,
copy,
copyToClipboard,
createPromise,
dragAndDropAnnotation,
firstPageOnTop,
Expand All @@ -30,21 +32,19 @@ import {
kbBigMoveLeft,
kbBigMoveRight,
kbBigMoveUp,
kbCopy,
kbGoToBegin,
kbGoToEnd,
kbModifierDown,
kbModifierUp,
kbPaste,
kbRedo,
kbSelectAll,
kbUndo,
loadAndWait,
paste,
pasteFromClipboard,
scrollIntoView,
switchToEditor,
waitForAnnotationEditorLayer,
waitForEvent,
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
Expand All @@ -53,16 +53,6 @@ import {
} from "./test_utils.mjs";
import { PNG } from "pngjs";

const copyPaste = async page => {
let promise = waitForEvent(page, "copy");
await kbCopy(page);
await promise;

promise = waitForEvent(page, "paste");
await kbPaste(page);
await promise;
};

const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
Expand Down Expand Up @@ -187,7 +177,8 @@ describe("FreeText Editor", () => {
);

await waitForSelectedEditor(page, getEditorSelector(0));
await copyPaste(page);
await copy(page);
await paste(page);
await page.waitForSelector(getEditorSelector(1), {
visible: true,
});
Expand All @@ -203,7 +194,8 @@ describe("FreeText Editor", () => {

expect(pastedContent).withContext(`In ${browserName}`).toEqual(content);

await copyPaste(page);
await copy(page);
await paste(page);
await page.waitForSelector(getEditorSelector(2), {
visible: true,
});
Expand Down Expand Up @@ -263,7 +255,8 @@ describe("FreeText Editor", () => {
);

await waitForSelectedEditor(page, getEditorSelector(3));
await copyPaste(page);
await copy(page);
await paste(page);
await page.waitForSelector(getEditorSelector(4), {
visible: true,
});
Expand All @@ -276,9 +269,7 @@ describe("FreeText Editor", () => {
);

for (let i = 0; i < 2; i++) {
const promise = waitForEvent(page, "paste");
await kbPaste(page);
await promise;
await paste(page);
await page.waitForSelector(getEditorSelector(5 + i));
}

Expand Down Expand Up @@ -597,7 +588,8 @@ describe("FreeText Editor", () => {
.withContext(`In ${browserName}`)
.toEqual([0, 1, 3]);

await copyPaste(page);
await copy(page);
await paste(page);
await page.waitForSelector(getEditorSelector(6), {
visible: true,
});
Expand Down Expand Up @@ -1275,7 +1267,8 @@ describe("FreeText Editor", () => {
);
await waitForSelectedEditor(page, getEditorSelector(1));

await copyPaste(page);
await copy(page);
await paste(page);
await page.waitForSelector(getEditorSelector(6), {
visible: true,
});
Expand Down Expand Up @@ -3425,14 +3418,11 @@ describe("FreeText Editor", () => {
);

await select(0);
await pasteFromClipboard(
page,
{
"text/html": "<b>Bold Foo</b>",
"text/plain": "Foo",
},
`${editorSelector} .internal`
);
await copyToClipboard(page, {
"text/html": "<b>Bold Foo</b>",
"text/plain": "Foo",
});
await pasteFromClipboard(page, `${editorSelector} .internal`);

let lastText = data;

Expand All @@ -3442,28 +3432,20 @@ describe("FreeText Editor", () => {
expect(text).withContext(`In ${browserName}`).toEqual(lastText);

await select(3);
await pasteFromClipboard(
page,
{
"text/html": "<b>Bold Bar</b><br><b>Oof</b>",
"text/plain": "Bar\nOof",
},
`${editorSelector} .internal`
);
await copyToClipboard(page, {
"text/html": "<b>Bold Bar</b><br><b>Oof</b>",
"text/plain": "Bar\nOof",
});
await pasteFromClipboard(page, `${editorSelector} .internal`);

await waitForTextChange(lastText, editorSelector);
text = await getText(editorSelector);
lastText = `FooBar\nOof${data}`;
expect(text).withContext(`In ${browserName}`).toEqual(lastText);

await select(0);
await pasteFromClipboard(
page,
{
"text/html": "<b>basic html</b>",
},
`${editorSelector} .internal`
);
await copyToClipboard(page, { "text/html": "<b>basic html</b>" });
await pasteFromClipboard(page, `${editorSelector} .internal`);

// Nothing should change, so it's hard to wait on something.
// eslint-disable-next-line no-restricted-syntax
Expand All @@ -3477,15 +3459,12 @@ describe("FreeText Editor", () => {
const prevHTML = await getHTML();

// Try to paste an image.
await pasteFromClipboard(
page,
{
"image/png":
// 1x1 transparent png.
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
},
`${editorSelector} .internal`
);
await copyToClipboard(page, {
"image/png":
// 1x1 transparent png.
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
});
await pasteFromClipboard(page, `${editorSelector} .internal`);

// Nothing should change, so it's hard to wait on something.
// eslint-disable-next-line no-restricted-syntax
Expand All @@ -3505,14 +3484,11 @@ describe("FreeText Editor", () => {
});

const fooBar = "Foo\nBar\nOof";
await pasteFromClipboard(
page,
{
"text/html": "<b>html</b>",
"text/plain": fooBar,
},
`${editorSelector} .internal`
);
await copyToClipboard(page, {
"text/html": "<b>html</b>",
"text/plain": fooBar,
});
await pasteFromClipboard(page, `${editorSelector} .internal`);

await waitForTextChange("", editorSelector);
text = await getText(editorSelector);
Expand Down
23 changes: 11 additions & 12 deletions test/integration/stamp_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ import {
applyFunctionToEditor,
awaitPromise,
closePages,
copy,
copyToClipboard,
getEditorDimensions,
getEditorSelector,
getFirstSerialized,
getRect,
getSerialized,
kbBigMoveDown,
kbBigMoveRight,
kbCopy,
kbPaste,
kbSelectAll,
kbUndo,
loadAndWait,
paste,
pasteFromClipboard,
scrollIntoView,
serializeBitmapDimensions,
Expand Down Expand Up @@ -78,12 +79,10 @@ const copyImage = async (page, imagePath, number) => {
const data = fs
.readFileSync(path.join(__dirname, imagePath))
.toString("base64");
await pasteFromClipboard(
page,
{ "image/png": `data:image/png;base64,${data}` },
"",
500
);

await copyToClipboard(page, { "image/png": `data:image/png;base64,${data}` });
await pasteFromClipboard(page);

await waitForImage(page, getEditorSelector(number));
};

Expand Down Expand Up @@ -570,13 +569,13 @@ describe("Stamp Editor", () => {
await page1.click("#editorStamp");

await copyImage(page1, "../images/firefox_logo.png", 0);
await kbCopy(page1);
await copy(page1);

const [, page2] = pages2[i];
await page2.bringToFront();
await page2.click("#editorStamp");

await kbPaste(page2);
await paste(page2);

await waitForImage(page2, getEditorSelector(0));
}
Expand Down Expand Up @@ -831,8 +830,8 @@ describe("Stamp Editor", () => {
);
await page.waitForSelector(`${getEditorSelector(0)} .altText.done`);

await kbCopy(page);
await kbPaste(page);
await copy(page);
await paste(page);
await page.waitForSelector(`${getEditorSelector(1)} .altText.done`);
await waitForSerialized(page, 2);

Expand Down
Loading