mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Refactor the copy/paste logic in the integration tests
The integration tests are currently not consistent in how they do copy/pasting: some tests use the `kbCopy`/`kbPaste` functions with waiting for the event inline, some have their own helper function to combine those actions and some even call `kbCopy`/`kbPaste` without waiting for the event at all (which can cause intermittent failures). This commit fixes the issues by providing a set of four helper functions that all tests use and that abstract e.g. waiting for the event away from the caller. This makes the invididual tests simpler and consistent, reduces code duplication and fixes possible intermittent failures due to not waiting for events to trigger.
This commit is contained in:
parent
2fbd61944b
commit
55ba4aa66a
4 changed files with 69 additions and 85 deletions
|
@ -292,7 +292,13 @@ async function mockClipboard(pages) {
|
|||
);
|
||||
}
|
||||
|
||||
async function pasteFromClipboard(page, data, selector, timeout = 100) {
|
||||
async function copy(page) {
|
||||
const promise = waitForEvent(page, "copy");
|
||||
await kbCopy(page);
|
||||
await promise;
|
||||
}
|
||||
|
||||
async function copyToClipboard(page, data) {
|
||||
await page.evaluate(async dat => {
|
||||
const items = Object.create(null);
|
||||
for (const [type, value] of Object.entries(dat)) {
|
||||
|
@ -305,7 +311,15 @@ async function pasteFromClipboard(page, data, selector, timeout = 100) {
|
|||
}
|
||||
await navigator.clipboard.write([new ClipboardItem(items)]);
|
||||
}, data);
|
||||
}
|
||||
|
||||
async function paste(page) {
|
||||
const promise = waitForEvent(page, "paste");
|
||||
await kbPaste(page);
|
||||
await promise;
|
||||
}
|
||||
|
||||
async function pasteFromClipboard(page, selector = null) {
|
||||
const validator = e => e.clipboardData.items.length !== 0;
|
||||
let hasPasteEvent = false;
|
||||
while (!hasPasteEvent) {
|
||||
|
@ -634,6 +648,8 @@ export {
|
|||
clearInput,
|
||||
closePages,
|
||||
closeSinglePage,
|
||||
copy,
|
||||
copyToClipboard,
|
||||
createPromise,
|
||||
dragAndDropAnnotation,
|
||||
firstPageOnTop,
|
||||
|
@ -654,7 +670,6 @@ export {
|
|||
kbBigMoveLeft,
|
||||
kbBigMoveRight,
|
||||
kbBigMoveUp,
|
||||
kbCopy,
|
||||
kbDeleteLastWord,
|
||||
kbFocusNext,
|
||||
kbFocusPrevious,
|
||||
|
@ -662,12 +677,12 @@ export {
|
|||
kbGoToEnd,
|
||||
kbModifierDown,
|
||||
kbModifierUp,
|
||||
kbPaste,
|
||||
kbRedo,
|
||||
kbSelectAll,
|
||||
kbUndo,
|
||||
loadAndWait,
|
||||
mockClipboard,
|
||||
paste,
|
||||
pasteFromClipboard,
|
||||
scrollIntoView,
|
||||
serializeBitmapDimensions,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue