From 5647eaf860e8c4af122b2754415d2be667bb99b9 Mon Sep 17 00:00:00 2001 From: David-Emmanuel DIVERNOIS Date: Thu, 23 Sep 2021 11:24:38 +0200 Subject: [PATCH] WIP: Adding support for mouse wheel events --- .../assistive-playwright-client/src/vm/mouse.ts | 4 ++-- components/assistive-webdriver/test/helpers/vmMock.ts | 2 ++ components/vm-providers/src/vm/qemu/qemu.ts | 5 +++++ components/vm-providers/src/vm/virtualbox/vm.ts | 11 +++++++++++ components/vm-providers/src/vm/vmInterface.ts | 7 +++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/components/assistive-playwright-client/src/vm/mouse.ts b/components/assistive-playwright-client/src/vm/mouse.ts index c1f69c51..f0015c20 100644 --- a/components/assistive-playwright-client/src/vm/mouse.ts +++ b/components/assistive-playwright-client/src/vm/mouse.ts @@ -57,8 +57,8 @@ export class VMMouse implements Mouse { public calibration: CalibrationResult ) {} - wheel(deltaX: number, deltaY: number): Promise { - throw new Error("Method not implemented yet."); + async wheel(deltaX: number, deltaY: number): Promise { + await this.vm.sendMouseWheelEvent(deltaX, deltaY); } /** diff --git a/components/assistive-webdriver/test/helpers/vmMock.ts b/components/assistive-webdriver/test/helpers/vmMock.ts index 2d8ffb03..4ba8cd51 100644 --- a/components/assistive-webdriver/test/helpers/vmMock.ts +++ b/components/assistive-webdriver/test/helpers/vmMock.ts @@ -50,6 +50,7 @@ export interface VMMock extends VM { sendMouseMoveEvent: AsyncFnMock; sendMouseDownEvent: AsyncFnMock; sendMouseUpEvent: AsyncFnMock; + sendMouseWheelEvent: AsyncFnMock; takePNGScreenshot: AsyncFnMock; } @@ -64,5 +65,6 @@ export const createVMMock = ( sendMouseDownEvent: asyncFnMock(`${vmName}.sendMouseDownEvent`), sendMouseMoveEvent: asyncFnMock(`${vmName}.sendMouseMoveEvent`), sendMouseUpEvent: asyncFnMock(`${vmName}.sendMouseUpEvent`), + sendMouseWheelEvent: asyncFnMock(`${vmName}.sendMouseWheelEvent`), takePNGScreenshot: asyncFnMock(`${vmName}.takePNGScreenshot`) }); diff --git a/components/vm-providers/src/vm/qemu/qemu.ts b/components/vm-providers/src/vm/qemu/qemu.ts index 381aea33..c30a3c37 100644 --- a/components/vm-providers/src/vm/qemu/qemu.ts +++ b/components/vm-providers/src/vm/qemu/qemu.ts @@ -282,6 +282,11 @@ export class QEMUVM implements VM { }); } + async sendMouseWheelEvent(deltaX: number, deltaY: number): Promise { + // TODO: implement this + throw new Error("Method not implemented."); + } + async sendMouseDownEvent(button: MouseButton): Promise { await this._sendCommand({ execute: "input-send-event", diff --git a/components/vm-providers/src/vm/virtualbox/vm.ts b/components/vm-providers/src/vm/virtualbox/vm.ts index b584bb5d..61a33379 100644 --- a/components/vm-providers/src/vm/virtualbox/vm.ts +++ b/components/vm-providers/src/vm/virtualbox/vm.ts @@ -209,6 +209,17 @@ export class VirtualboxVM implements VM { await this.vboxMouse!.putMouseEvent(0, 0, 0, 0, this.vboxMouseButtonState); } + async sendMouseWheelEvent(deltaX: number, deltaY: number): Promise { + // TODO: check if it works correctly + await this.vboxMouse!.putMouseEvent( + 0, + 0, + deltaY, + deltaX, + this.vboxMouseButtonState + ); + } + async takePNGScreenshot(): Promise { const resolution = await this.vboxDisplay!.getScreenResolution(0); const screenshot = await this.vboxDisplay!.takeScreenShotToArray( diff --git a/components/vm-providers/src/vm/vmInterface.ts b/components/vm-providers/src/vm/vmInterface.ts index 0684f617..87f42df1 100644 --- a/components/vm-providers/src/vm/vmInterface.ts +++ b/components/vm-providers/src/vm/vmInterface.ts @@ -142,6 +142,13 @@ export interface VM { */ sendMouseUpEvent(button: MouseButton): Promise; + /** + * Sends a mouse wheel event to the virtual machine. + * @param deltaX - amount to scroll horizontally + * @param deltaY - amount to scroll vertically + */ + sendMouseWheelEvent(deltaX: number, deltaY: number): Promise; + /** * Takes a screenshot of the virtual machine and returns the corresponding PNG image. */