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

Paste: add e2e tests for Webkit and Firefox #53482

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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
33 changes: 16 additions & 17 deletions packages/e2e-test-utils-playwright/src/page-utils/press-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@ async function emulateClipboard( page: Page, type: 'copy' | 'cut' | 'paste' ) {
const canvasDoc =
// @ts-ignore
document.activeElement?.contentDocument ?? document;
const clipboardDataTransfer = new DataTransfer();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firefox seems to clone this instance, so using this one doesn't work. We have to use event.clipboardData.

const event = new ClipboardEvent( _type, {
bubbles: true,
cancelable: true,
clipboardData: new DataTransfer(),
} );

if ( ! event.clipboardData ) {
throw new Error( 'ClipboardEvent.clipboardData is null' );
}

if ( _type === 'paste' ) {
clipboardDataTransfer.setData(
event.clipboardData.setData(
'text/plain',
_clipboardData.plainText
);
clipboardDataTransfer.setData(
'text/html',
_clipboardData.html
);
event.clipboardData.setData( 'text/html', _clipboardData.html );
} else {
const selection = canvasDoc.defaultView.getSelection()!;
const plainText = selection.toString();
Expand All @@ -78,21 +83,15 @@ async function emulateClipboard( page: Page, type: 'copy' | 'cut' | 'paste' ) {
)
.join( '' );
}
clipboardDataTransfer.setData( 'text/plain', plainText );
clipboardDataTransfer.setData( 'text/html', html );
event.clipboardData.setData( 'text/plain', plainText );
event.clipboardData.setData( 'text/html', html );
}

canvasDoc.activeElement?.dispatchEvent(
new ClipboardEvent( _type, {
bubbles: true,
cancelable: true,
clipboardData: clipboardDataTransfer,
} )
);
canvasDoc.activeElement.dispatchEvent( event );

return {
plainText: clipboardDataTransfer.getData( 'text/plain' ),
html: clipboardDataTransfer.getData( 'text/html' ),
plainText: event.clipboardData.getData( 'text/plain' ),
html: event.clipboardData.getData( 'text/html' ),
};
},
[ type, clipboardDataHolder ] as const
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading