From 6d3bb458f9cf4ba6318b5969febf741d70924194 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Tue, 23 Nov 2021 02:55:32 -0500 Subject: [PATCH] fix(firefox): round down mouse coordinates (#10483) --- .../src/server/firefox/ffInput.ts | 16 ++++++++-------- tests/page/page-mouse.spec.ts | 10 ++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/playwright-core/src/server/firefox/ffInput.ts b/packages/playwright-core/src/server/firefox/ffInput.ts index cdeb6cd7eb..b0408c80b9 100644 --- a/packages/playwright-core/src/server/firefox/ffInput.ts +++ b/packages/playwright-core/src/server/firefox/ffInput.ts @@ -113,8 +113,8 @@ export class RawMouseImpl implements input.RawMouse { type: 'mousemove', button: 0, buttons: toButtonsMask(buttons), - x, - y, + x: Math.floor(x), + y: Math.floor(y), modifiers: toModifiersMask(modifiers) }); } @@ -124,8 +124,8 @@ export class RawMouseImpl implements input.RawMouse { type: 'mousedown', button: toButtonNumber(button), buttons: toButtonsMask(buttons), - x, - y, + x: Math.floor(x), + y: Math.floor(y), modifiers: toModifiersMask(modifiers), clickCount }); @@ -136,8 +136,8 @@ export class RawMouseImpl implements input.RawMouse { type: 'mouseup', button: toButtonNumber(button), buttons: toButtonsMask(buttons), - x, - y, + x: Math.floor(x), + y: Math.floor(y), modifiers: toModifiersMask(modifiers), clickCount }); @@ -149,8 +149,8 @@ export class RawMouseImpl implements input.RawMouse { await this._client.send('Page.dispatchWheelEvent', { deltaX, deltaY, - x, - y, + x: Math.floor(x), + y: Math.floor(y), deltaZ: 0, modifiers: toModifiersMask(modifiers) }); diff --git a/tests/page/page-mouse.spec.ts b/tests/page/page-mouse.spec.ts index 512ed2fde8..a083230a09 100644 --- a/tests/page/page-mouse.spec.ts +++ b/tests/page/page-mouse.spec.ts @@ -164,3 +164,13 @@ it('should tween mouse movement', async ({ page, browserName, isAndroid }) => { [200, 300] ]); }); + +it('should always round down', async ({ page, browserName, isAndroid }) => { + await page.evaluate(() => { + document.addEventListener('mousedown', event => { + window['result'] = [event.clientX, event.clientY]; + }); + }); + await page.mouse.click(50.1, 50.9); + expect(await page.evaluate('result')).toEqual([50, 50]); +});