From 28bebde344d5d8c3a85877bfb7710bc83e0e0e14 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Tue, 28 Jan 2025 08:11:16 +0100 Subject: [PATCH 1/4] test: failing dblclick test --- tests/input/__snapshots__/test_input.ambr | 76 +++++++++++++++++++++ tests/input/test_input.py | 80 +++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/tests/input/__snapshots__/test_input.ambr b/tests/input/__snapshots__/test_input.ambr index 77da2e5f51..93f59410ba 100644 --- a/tests/input/__snapshots__/test_input.ambr +++ b/tests/input/__snapshots__/test_input.ambr @@ -951,6 +951,82 @@ 'type': 'success', }) # --- +# name: test_input_performActionsEmitsDblClicks + dict({ + 'result': dict({ + 'type': 'array', + 'value': list([ + dict({ + 'type': 'object', + 'value': list([ + list([ + 'event', + dict({ + 'type': 'string', + 'value': 'dblclick', + }), + ]), + list([ + 'button', + dict({ + 'type': 'number', + 'value': 0, + }), + ]), + list([ + 'buttons', + dict({ + 'type': 'number', + 'value': 0, + }), + ]), + list([ + 'clickCount', + dict({ + 'type': 'number', + 'value': 2, + }), + ]), + ]), + }), + dict({ + 'type': 'object', + 'value': list([ + list([ + 'event', + dict({ + 'type': 'string', + 'value': 'dblclick', + }), + ]), + list([ + 'button', + dict({ + 'type': 'number', + 'value': 0, + }), + ]), + list([ + 'buttons', + dict({ + 'type': 'number', + 'value': 0, + }), + ]), + list([ + 'clickCount', + dict({ + 'type': 'number', + 'value': 2, + }), + ]), + ]), + }), + ]), + }), + 'type': 'success', + }) +# --- # name: test_input_performActionsEmitsDragging dict({ 'result': dict({ diff --git a/tests/input/test_input.py b/tests/input/test_input.py index 77daea5c45..18f108ce3a 100644 --- a/tests/input/test_input.py +++ b/tests/input/test_input.py @@ -91,6 +91,21 @@ """ +DBL_CLICK_SCRIPT = """ +
+ +""" + DRAG_SCRIPT = """
Date: Thu, 30 Jan 2025 16:24:27 +0100 Subject: [PATCH 2/4] group clicks not more than by 2 --- src/bidiMapper/modules/input/InputSource.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bidiMapper/modules/input/InputSource.ts b/src/bidiMapper/modules/input/InputSource.ts index 58d907f632..0d61e43c27 100644 --- a/src/bidiMapper/modules/input/InputSource.ts +++ b/src/bidiMapper/modules/input/InputSource.ts @@ -158,6 +158,12 @@ export class PointerSource { storedContext = context; } ++storedContext.count; + if (storedContext.count > 2) { + // There is no API for triple clicks, so a series of clicks should be grouped in + // pairs. + // https://github.com/GoogleChromeLabs/chromium-bidi/issues/3043 + storedContext.count = 1; + } this.#clickContexts.set(button, storedContext); return storedContext.count; } From 37a4e2e4192bc1b48faa269036d58643659bc73a Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Thu, 30 Jan 2025 16:24:27 +0100 Subject: [PATCH 3/4] group clicks not more than by 2 --- tests/input/test_input.py | 90 +++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/tests/input/test_input.py b/tests/input/test_input.py index 18f108ce3a..95c8e2a2eb 100644 --- a/tests/input/test_input.py +++ b/tests/input/test_input.py @@ -226,10 +226,9 @@ async def test_input_performActionsEmitsKeyboardEvents(websocket, context_id, @pytest.mark.asyncio -async def test_input_performActionsEmitsDblClicks(websocket, context_id, - html, activate_main_tab, - query_selector, - snapshot): +async def test_input_performActionsEmitsDblClicks(websocket, context_id, html, + activate_main_tab, + query_selector, snapshot): await goto_url(websocket, context_id, html(DBL_CLICK_SCRIPT)) await activate_main_tab() await reset_mouse(websocket, context_id) @@ -241,22 +240,31 @@ async def test_input_performActionsEmitsDblClicks(websocket, context_id, "method": "input.performActions", "params": { "context": context_id, - "actions": [ - {"type":"pointer", - "id":"__puppeteer_mouse", - "actions":[ - {"type":"pointerMove", - "x": 0, - "y": 0, - "origin": { - "type": "element", - "element": target_element - }}, - {"type":"pointerDown","button":0}, - {"type":"pointerUp","button":0}, - {"type":"pointerDown","button":0}, - {"type":"pointerUp","button":0} - ]}] + "actions": [{ + "type": "pointer", + "id": "__puppeteer_mouse", + "actions": [{ + "type": "pointerMove", + "x": 0, + "y": 0, + "origin": { + "type": "element", + "element": target_element + } + }, { + "type": "pointerDown", + "button": 0 + }, { + "type": "pointerUp", + "button": 0 + }, { + "type": "pointerDown", + "button": 0 + }, { + "type": "pointerUp", + "button": 0 + }] + }] } }) @@ -265,22 +273,31 @@ async def test_input_performActionsEmitsDblClicks(websocket, context_id, "method": "input.performActions", "params": { "context": context_id, - "actions": [ - {"type":"pointer", - "id":"__puppeteer_mouse", - "actions":[ - {"type":"pointerMove", - "x": 0, - "y": 0, - "origin": { - "type": "element", - "element": target_element - }}, - {"type":"pointerDown","button":0}, - {"type":"pointerUp","button":0}, - {"type":"pointerDown","button":0}, - {"type":"pointerUp","button":0} - ]}] + "actions": [{ + "type": "pointer", + "id": "__puppeteer_mouse", + "actions": [{ + "type": "pointerMove", + "x": 0, + "y": 0, + "origin": { + "type": "element", + "element": target_element + } + }, { + "type": "pointerDown", + "button": 0 + }, { + "type": "pointerUp", + "button": 0 + }, { + "type": "pointerDown", + "button": 0 + }, { + "type": "pointerUp", + "button": 0 + }] + }] } }) @@ -289,7 +306,6 @@ async def test_input_performActionsEmitsDblClicks(websocket, context_id, assert result == snapshot(exclude=props("realm")) - @pytest.mark.asyncio async def test_input_performActionsEmitsDragging(websocket, context_id, html, query_selector, snapshot, From aaed398286e6f208963f9210ed89490c48d3d7af Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Fri, 31 Jan 2025 11:39:03 +0100 Subject: [PATCH 4/4] reset click counter between performActions --- src/bidiMapper/modules/input/InputProcessor.ts | 2 ++ src/bidiMapper/modules/input/InputSource.ts | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/bidiMapper/modules/input/InputProcessor.ts b/src/bidiMapper/modules/input/InputProcessor.ts index 3d48aac745..d63ff0a84e 100644 --- a/src/bidiMapper/modules/input/InputProcessor.ts +++ b/src/bidiMapper/modules/input/InputProcessor.ts @@ -263,6 +263,8 @@ export class InputProcessor { `Expected input source ${action.id} to be ${source.subtype}; got ${action.parameters.pointerType}.`, ); } + // https://github.com/GoogleChromeLabs/chromium-bidi/issues/3043 + source.resetClickCount(); break; } default: diff --git a/src/bidiMapper/modules/input/InputSource.ts b/src/bidiMapper/modules/input/InputSource.ts index 0d61e43c27..76a4f39daa 100644 --- a/src/bidiMapper/modules/input/InputSource.ts +++ b/src/bidiMapper/modules/input/InputSource.ts @@ -158,12 +158,6 @@ export class PointerSource { storedContext = context; } ++storedContext.count; - if (storedContext.count > 2) { - // There is no API for triple clicks, so a series of clicks should be grouped in - // pairs. - // https://github.com/GoogleChromeLabs/chromium-bidi/issues/3043 - storedContext.count = 1; - } this.#clickContexts.set(button, storedContext); return storedContext.count; } @@ -171,6 +165,18 @@ export class PointerSource { getClickCount(button: number) { return this.#clickContexts.get(button)?.count ?? 0; } + + /** + * Resets click count. Resets consequent click counter. Prevents grouping clicks in + * different `performActions` calls, so that they are not grouped as double, triple etc + * clicks. Required for https://github.com/GoogleChromeLabs/chromium-bidi/issues/3043. + */ + resetClickCount(): void { + this.#clickContexts = new Map< + number, + InstanceType + >(); + } // --- Platform-specific state ends here --- }