From 8b5e146b9074cebcf534b28dc403a9ba68bd33ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 12 Dec 2021 19:01:45 +0100 Subject: [PATCH] test(mouse): add a test for pointerdown event with custom button (#10697) --- .../src/server/webkit/wkInput.ts | 4 +-- tests/page/page-mouse.spec.ts | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/server/webkit/wkInput.ts b/packages/playwright-core/src/server/webkit/wkInput.ts index c2576dc7f9..16ff4c162f 100644 --- a/packages/playwright-core/src/server/webkit/wkInput.ts +++ b/packages/playwright-core/src/server/webkit/wkInput.ts @@ -40,9 +40,9 @@ function toButtonsMask(buttons: Set): 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; } diff --git a/tests/page/page-mouse.spec.ts b/tests/page/page-mouse.spec.ts index a083230a09..7ce7bf2dce 100644 --- a/tests/page/page-mouse.spec.ts +++ b/tests/page/page-mouse.spec.ts @@ -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(`
Click me
`); + 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');