chore: fix BiDi mouse move implementation (#10956)
This commit is contained in:
parent
7b5eabcc37
commit
c505c85b31
@ -458,7 +458,7 @@ const getBidiButton = (button: MouseButton) => {
|
|||||||
*/
|
*/
|
||||||
export class BidiMouse extends Mouse {
|
export class BidiMouse extends Mouse {
|
||||||
#context: BrowsingContext;
|
#context: BrowsingContext;
|
||||||
#lastMovePoint?: Point;
|
#lastMovePoint: Point = {x: 0, y: 0};
|
||||||
|
|
||||||
constructor(context: BrowsingContext) {
|
constructor(context: BrowsingContext) {
|
||||||
super();
|
super();
|
||||||
@ -466,7 +466,7 @@ export class BidiMouse extends Mouse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override async reset(): Promise<void> {
|
override async reset(): Promise<void> {
|
||||||
this.#lastMovePoint = undefined;
|
this.#lastMovePoint = {x: 0, y: 0};
|
||||||
await this.#context.connection.send('input.releaseActions', {
|
await this.#context.connection.send('input.releaseActions', {
|
||||||
context: this.#context.id,
|
context: this.#context.id,
|
||||||
});
|
});
|
||||||
@ -477,25 +477,35 @@ export class BidiMouse extends Mouse {
|
|||||||
y: number,
|
y: number,
|
||||||
options: Readonly<BidiMouseMoveOptions> = {}
|
options: Readonly<BidiMouseMoveOptions> = {}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// https://w3c.github.io/webdriver-bidi/#command-input-performActions:~:text=input.PointerMoveAction%20%3D%20%7B%0A%20%20type%3A%20%22pointerMove%22%2C%0A%20%20x%3A%20js%2Dint%2C
|
const from = this.#lastMovePoint;
|
||||||
this.#lastMovePoint = {
|
const to = {
|
||||||
x: Math.round(x),
|
x: Math.round(x),
|
||||||
y: Math.round(y),
|
y: Math.round(y),
|
||||||
};
|
};
|
||||||
|
const actions: Bidi.Input.PointerSourceAction[] = [];
|
||||||
|
const steps = options.steps ?? 0;
|
||||||
|
for (let i = 0; i < steps; ++i) {
|
||||||
|
actions.push({
|
||||||
|
type: ActionType.PointerMove,
|
||||||
|
x: from.x + (to.x - from.x) * (i / steps),
|
||||||
|
y: from.y + (to.y - from.y) * (i / steps),
|
||||||
|
origin: options.origin,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
actions.push({
|
||||||
|
type: ActionType.PointerMove,
|
||||||
|
...to,
|
||||||
|
origin: options.origin,
|
||||||
|
});
|
||||||
|
// https://w3c.github.io/webdriver-bidi/#command-input-performActions:~:text=input.PointerMoveAction%20%3D%20%7B%0A%20%20type%3A%20%22pointerMove%22%2C%0A%20%20x%3A%20js%2Dint%2C
|
||||||
|
this.#lastMovePoint = to;
|
||||||
await this.#context.connection.send('input.performActions', {
|
await this.#context.connection.send('input.performActions', {
|
||||||
context: this.#context.id,
|
context: this.#context.id,
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
type: SourceActionsType.Pointer,
|
type: SourceActionsType.Pointer,
|
||||||
id: InputId.Mouse,
|
id: InputId.Mouse,
|
||||||
actions: [
|
actions,
|
||||||
{
|
|
||||||
type: ActionType.PointerMove,
|
|
||||||
...this.#lastMovePoint,
|
|
||||||
duration: (options.steps ?? 0) * 50,
|
|
||||||
origin: options.origin,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -131,6 +131,12 @@
|
|||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["webDriverBiDi"],
|
||||||
"expectations": ["PASS"]
|
"expectations": ["PASS"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"testIdPattern": "[mouse.spec] *",
|
||||||
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
"parameters": ["webDriverBiDi"],
|
||||||
|
"expectations": ["PASS"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[navigation.spec] *",
|
"testIdPattern": "[navigation.spec] *",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
@ -816,58 +822,16 @@
|
|||||||
"expectations": ["SKIP"]
|
"expectations": ["SKIP"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[mouse.spec] Mouse should click the document",
|
"testIdPattern": "[mouse.spec] Mouse should not throw if buttons are pressed twice",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["cdp"],
|
||||||
"expectations": ["PASS"]
|
"expectations": ["FAIL"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[mouse.spec] Mouse should not throw if clicking in parallel",
|
"testIdPattern": "[mouse.spec] Mouse should reset properly",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["cdp"],
|
||||||
"expectations": ["PASS"]
|
"expectations": ["FAIL", "TIMEOUT"]
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should resize the textarea",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should select the text with mouse",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should send mouse wheel events",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should set modifier keys on click",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should trigger hover state",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should trigger hover state with removed window.Node",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should work with mobile viewports and cross process navigations",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[navigation.spec] navigation \"after each\" hook for \"should work with both domcontentloaded and load\"",
|
"testIdPattern": "[navigation.spec] navigation \"after each\" hook for \"should work with both domcontentloaded and load\"",
|
||||||
@ -2429,72 +2393,18 @@
|
|||||||
"parameters": ["cdp", "firefox"],
|
"parameters": ["cdp", "firefox"],
|
||||||
"expectations": ["SKIP"]
|
"expectations": ["SKIP"]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should reset properly",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["cdp", "firefox"],
|
|
||||||
"expectations": ["SKIP"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should resize the textarea",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["firefox", "webDriverBiDi"],
|
|
||||||
"expectations": ["FAIL", "PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should select the text with mouse",
|
|
||||||
"platforms": ["win32"],
|
|
||||||
"parameters": ["cdp", "chrome"],
|
|
||||||
"expectations": ["FAIL", "PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should select the text with mouse",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["chrome", "webDriverBiDi"],
|
|
||||||
"expectations": ["FAIL", "PASS"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"testIdPattern": "[mouse.spec] Mouse should send mouse wheel events",
|
"testIdPattern": "[mouse.spec] Mouse should send mouse wheel events",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["cdp", "firefox"],
|
"parameters": ["cdp", "firefox"],
|
||||||
"expectations": ["FAIL"]
|
"expectations": ["FAIL"]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should send mouse wheel events",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["chrome", "webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should set modifier keys on click",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["chrome", "webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should trigger hover state",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["cdp", "firefox"],
|
|
||||||
"expectations": ["FAIL", "PASS"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"testIdPattern": "[mouse.spec] Mouse should trigger hover state with removed window.Node",
|
"testIdPattern": "[mouse.spec] Mouse should trigger hover state with removed window.Node",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["cdp", "firefox"],
|
"parameters": ["cdp", "firefox"],
|
||||||
"expectations": ["FAIL"]
|
"expectations": ["FAIL"]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should tween mouse movement",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["cdp", "firefox"],
|
|
||||||
"expectations": ["FAIL", "PASS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[mouse.spec] Mouse should work with mobile viewports and cross process navigations",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["chrome", "webDriverBiDi"],
|
|
||||||
"expectations": ["PASS"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"testIdPattern": "[navigation.spec] navigation Frame.goto should navigate subframes",
|
"testIdPattern": "[navigation.spec] navigation Frame.goto should navigate subframes",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
@ -267,13 +267,13 @@ describe('Mouse', function () {
|
|||||||
|
|
||||||
expect(await page.evaluate('result')).toEqual({x: 30, y: 40});
|
expect(await page.evaluate('result')).toEqual({x: 30, y: 40});
|
||||||
});
|
});
|
||||||
it('should throw if buttons are pressed incorrectly', async () => {
|
it('should not throw if buttons are pressed twice', async () => {
|
||||||
const {page, server} = await getTestState();
|
const {page, server} = await getTestState();
|
||||||
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
|
||||||
await page.mouse.down();
|
await page.mouse.down();
|
||||||
await expect(page.mouse.down()).rejects.toBeInstanceOf(Error);
|
await page.mouse.down();
|
||||||
});
|
});
|
||||||
|
|
||||||
interface AddMouseDataListenersOptions {
|
interface AddMouseDataListenersOptions {
|
||||||
@ -303,6 +303,7 @@ describe('Mouse', function () {
|
|||||||
}
|
}
|
||||||
document.addEventListener('mouseup', mouseEventListener);
|
document.addEventListener('mouseup', mouseEventListener);
|
||||||
document.addEventListener('click', mouseEventListener);
|
document.addEventListener('click', mouseEventListener);
|
||||||
|
document.addEventListener('auxclick', mouseEventListener);
|
||||||
(window as unknown as {clicks: ClickData[]}).clicks = clicks;
|
(window as unknown as {clicks: ClickData[]}).clicks = clicks;
|
||||||
}, options);
|
}, options);
|
||||||
};
|
};
|
||||||
@ -366,7 +367,7 @@ describe('Mouse', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should reset properly', async () => {
|
it('should reset properly', async () => {
|
||||||
const {page, server} = await getTestState();
|
const {page, server, isChrome} = await getTestState();
|
||||||
|
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
|
||||||
@ -388,43 +389,71 @@ describe('Mouse', function () {
|
|||||||
clientY: 5,
|
clientY: 5,
|
||||||
clientX: 5,
|
clientX: 5,
|
||||||
};
|
};
|
||||||
expect(data).toMatchObject([
|
|
||||||
|
expect(data.slice(0, 2)).toMatchObject([
|
||||||
{
|
{
|
||||||
...commonAttrs,
|
...commonAttrs,
|
||||||
button: 0,
|
button: 2,
|
||||||
buttons: 6,
|
buttons: 5,
|
||||||
detail: 1,
|
detail: 1,
|
||||||
type: 'mouseup',
|
type: 'mouseup',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
...commonAttrs,
|
|
||||||
button: 0,
|
|
||||||
buttons: 6,
|
|
||||||
detail: 1,
|
|
||||||
type: 'click',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...commonAttrs,
|
|
||||||
button: 1,
|
|
||||||
buttons: 2,
|
|
||||||
detail: 0,
|
|
||||||
type: 'mouseup',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
...commonAttrs,
|
...commonAttrs,
|
||||||
button: 2,
|
button: 2,
|
||||||
|
buttons: 5,
|
||||||
|
detail: 1,
|
||||||
|
type: 'auxclick',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
// TODO(crbug/1485040): This should align with the firefox implementation.
|
||||||
|
if (isChrome) {
|
||||||
|
expect(data.slice(2)).toMatchObject([
|
||||||
|
{
|
||||||
|
...commonAttrs,
|
||||||
|
button: 1,
|
||||||
|
buttons: 1,
|
||||||
|
detail: 0,
|
||||||
|
type: 'mouseup',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...commonAttrs,
|
||||||
|
button: 0,
|
||||||
|
buttons: 0,
|
||||||
|
detail: 0,
|
||||||
|
type: 'mouseup',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
expect(data.slice(2)).toMatchObject([
|
||||||
|
{
|
||||||
|
...commonAttrs,
|
||||||
|
button: 1,
|
||||||
|
buttons: 1,
|
||||||
|
detail: 1,
|
||||||
|
type: 'mouseup',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...commonAttrs,
|
||||||
|
button: 1,
|
||||||
|
buttons: 1,
|
||||||
|
detail: 1,
|
||||||
|
type: 'auxclick',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...commonAttrs,
|
||||||
|
button: 0,
|
||||||
buttons: 0,
|
buttons: 0,
|
||||||
detail: 0,
|
detail: 1,
|
||||||
type: 'mouseup',
|
type: 'mouseup',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...commonAttrs,
|
...commonAttrs,
|
||||||
button: 0,
|
button: 0,
|
||||||
buttons: 0,
|
buttons: 0,
|
||||||
clientX: 0,
|
detail: 1,
|
||||||
clientY: 0,
|
type: 'click',
|
||||||
detail: 0,
|
|
||||||
type: 'mousemove',
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user