test(mouse): add a test for pointerdown event with custom button (#10697)

This commit is contained in:
Mateusz Burzyński 2021-12-12 19:01:45 +01:00 committed by GitHub
parent 105912e898
commit 8b5e146b90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View File

@ -40,9 +40,9 @@ function toButtonsMask(buttons: Set<types.MouseButton>): number {
let mask = 0;
if (buttons.has('left'))
mask |= 1;
if (buttons.has('middle'))
mask |= 2;
if (buttons.has('right'))
mask |= 2;
if (buttons.has('middle'))
mask |= 4;
return mask;
}

View File

@ -78,6 +78,38 @@ it('should dblclick the div', async ({ page, server }) => {
expect(event.button).toBe(0);
});
it('should pointerdown the div with a custom button', async ({ page, server, browserName }) => {
await page.setContent(`<div style='width: 100px; height: 100px;'>Click me</div>`);
await page.evaluate(() => {
window['pointerdownPromise'] = new Promise(resolve => {
document.querySelector('div').addEventListener('pointerdown', event => {
resolve({
type: event.type,
detail: event.detail,
clientX: event.clientX,
clientY: event.clientY,
isTrusted: event.isTrusted,
button: event.button,
buttons: event.buttons,
pointerId: event.pointerId,
});
});
});
});
await page.mouse.click(50, 60, {
button: 'middle'
});
const event = await page.evaluate(() => window['pointerdownPromise']);
expect(event.type).toBe('pointerdown');
expect(event.detail).toBe(browserName === 'webkit' ? 1 : 0);
expect(event.clientX).toBe(50);
expect(event.clientY).toBe(60);
expect(event.isTrusted).toBe(true);
expect(event.button).toBe(1);
expect(event.buttons).toBe(4);
expect(event.pointerId).toBe(browserName === 'firefox' ? 0 : 1);
});
it('should select the text with mouse', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/textarea.html');
await page.focus('textarea');