test: custom dataTransfer type (#20571)

#18013
This commit is contained in:
Yury Semikhatsky 2023-02-01 17:18:58 -08:00 committed by GitHub
parent f46883e58e
commit 8f229fac9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -390,3 +390,42 @@ async function trackEvents(target: ElementHandle) {
});
return eventsHandle;
}
it('should handle custom dataTransfer', async ({ page, browserName, isLinux, headless }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/18013' });
it.skip(browserName === 'webkit' && isLinux && headless);
await page.setContent(`<button draggable="true">Draggable</button>`);
const resultPromise = page.evaluate(() =>
new Promise(resolve => {
document.addEventListener('dragstart', event => {
event.dataTransfer!.setData('custom-type', 'Hello World');
}, false);
document.addEventListener('dragenter', event => {
event.preventDefault();
}, false);
document.addEventListener('dragover', event => {
event.preventDefault();
}, false);
document.addEventListener('drop', event => {
event.preventDefault();
resolve({
types: event.dataTransfer!.types,
data: event.dataTransfer!.getData('custom-type'),
});
}, false);
})
);
await page.hover('[draggable="true"]');
await page.mouse.down();
await page.mouse.move(100, 100);
await page.mouse.up();
await expect(resultPromise).resolves.toEqual({
types: ['custom-type'],
data: 'Hello World',
});
});