mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(mouse): set .buttons
correctly for basic mouse commands in Chrome (#10698)
Co-authored-by: Andrey Lushnikov <aslushnikov@gmail.com>
This commit is contained in:
parent
284f76357f
commit
b0cd5b1420
@ -22,7 +22,7 @@ import { macEditingCommands } from '../macEditingCommands';
|
|||||||
import { isString } from '../../utils/utils';
|
import { isString } from '../../utils/utils';
|
||||||
import { DragManager } from './crDragDrop';
|
import { DragManager } from './crDragDrop';
|
||||||
import { CRPage } from './crPage';
|
import { CRPage } from './crPage';
|
||||||
import { toModifiersMask } from './crProtocolHelper';
|
import { toButtonsMask, toModifiersMask } from './crProtocolHelper';
|
||||||
|
|
||||||
export class RawKeyboardImpl implements input.RawKeyboard {
|
export class RawKeyboardImpl implements input.RawKeyboard {
|
||||||
constructor(
|
constructor(
|
||||||
@ -101,6 +101,7 @@ export class RawMouseImpl implements input.RawMouse {
|
|||||||
await this._client.send('Input.dispatchMouseEvent', {
|
await this._client.send('Input.dispatchMouseEvent', {
|
||||||
type: 'mouseMoved',
|
type: 'mouseMoved',
|
||||||
button,
|
button,
|
||||||
|
buttons: toButtonsMask(buttons),
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
modifiers: toModifiersMask(modifiers)
|
modifiers: toModifiersMask(modifiers)
|
||||||
@ -120,6 +121,7 @@ export class RawMouseImpl implements input.RawMouse {
|
|||||||
await this._client.send('Input.dispatchMouseEvent', {
|
await this._client.send('Input.dispatchMouseEvent', {
|
||||||
type: 'mousePressed',
|
type: 'mousePressed',
|
||||||
button,
|
button,
|
||||||
|
buttons: toButtonsMask(buttons),
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
modifiers: toModifiersMask(modifiers),
|
modifiers: toModifiersMask(modifiers),
|
||||||
@ -135,6 +137,7 @@ export class RawMouseImpl implements input.RawMouse {
|
|||||||
await this._client.send('Input.dispatchMouseEvent', {
|
await this._client.send('Input.dispatchMouseEvent', {
|
||||||
type: 'mouseReleased',
|
type: 'mouseReleased',
|
||||||
button,
|
button,
|
||||||
|
buttons: toButtonsMask(buttons),
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
modifiers: toModifiersMask(modifiers),
|
modifiers: toModifiersMask(modifiers),
|
||||||
|
@ -102,3 +102,14 @@ export function toModifiersMask(modifiers: Set<types.KeyboardModifier>): number
|
|||||||
mask |= 8;
|
mask |= 8;
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toButtonsMask(buttons: Set<types.MouseButton>): number {
|
||||||
|
let mask = 0;
|
||||||
|
if (buttons.has('left'))
|
||||||
|
mask |= 1;
|
||||||
|
if (buttons.has('right'))
|
||||||
|
mask |= 2;
|
||||||
|
if (buttons.has('middle'))
|
||||||
|
mask |= 4;
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
@ -110,6 +110,40 @@ it('should pointerdown the div with a custom button', async ({ page, server, bro
|
|||||||
expect(event.pointerId).toBe(browserName === 'firefox' ? 0 : 1);
|
expect(event.pointerId).toBe(browserName === 'firefox' ? 0 : 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should report correct buttons property', async ({ page }) => {
|
||||||
|
await page.evaluate(() => {
|
||||||
|
(window as any).__EVENTS = [];
|
||||||
|
const handler = event => {
|
||||||
|
(window as any).__EVENTS.push({
|
||||||
|
type: event.type,
|
||||||
|
button: event.button,
|
||||||
|
buttons: event.buttons,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
window.addEventListener('mousedown', handler, false);
|
||||||
|
window.addEventListener('mouseup', handler, false);
|
||||||
|
});
|
||||||
|
await page.mouse.move(50, 60);
|
||||||
|
await page.mouse.down({
|
||||||
|
button: 'middle',
|
||||||
|
});
|
||||||
|
await page.mouse.down({
|
||||||
|
button: 'left',
|
||||||
|
});
|
||||||
|
await page.mouse.up({
|
||||||
|
button: 'middle',
|
||||||
|
});
|
||||||
|
await page.mouse.up({
|
||||||
|
button: 'left',
|
||||||
|
});
|
||||||
|
expect(await page.evaluate(() => (window as any).__EVENTS)).toEqual([
|
||||||
|
{ type: 'mousedown', button: 1, buttons: 4 },
|
||||||
|
{ type: 'mousedown', button: 0, buttons: 5 },
|
||||||
|
{ type: 'mouseup', button: 1, buttons: 1 },
|
||||||
|
{ type: 'mouseup', button: 0, buttons: 0 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('should select the text with mouse', async ({ page, server }) => {
|
it('should select the text with mouse', async ({ page, server }) => {
|
||||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||||
await page.focus('textarea');
|
await page.focus('textarea');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user