Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: group clicks in action #3052

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bidiMapper/modules/input/InputProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions src/bidiMapper/modules/input/InputSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you can just write :

this.#clickContexts = new Map()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double nit: this.#clickContexts.clear()?

InstanceType<typeof PointerSource.ClickContext>
>();
}
// --- Platform-specific state ends here ---
}

Expand Down
76 changes: 76 additions & 0 deletions tests/input/__snapshots__/test_input.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
96 changes: 96 additions & 0 deletions tests/input/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@
</script>
"""

DBL_CLICK_SCRIPT = """
<div style="height: 2000px; width: 10px"></div>
<script>
var allEvents = [];
window.addEventListener("dblclick", (event) => {
allEvents.push({
event: "dblclick",
button: event.button,
buttons: event.buttons,
clickCount: event.detail,
});
});
</script>
"""

DRAG_SCRIPT = """
<div
style="height: 100px; width: 100px; background-color: red"
Expand Down Expand Up @@ -210,6 +225,87 @@ async def test_input_performActionsEmitsKeyboardEvents(websocket, context_id,
assert result == snapshot(exclude=props("realm"))


@pytest.mark.asyncio
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)

target_element = await query_selector('div')

await execute_command(
websocket, {
"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
}]
}]
}
})

await execute_command(
websocket, {
"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
}]
}]
}
})

result = await get_events(websocket, context_id)

assert result == snapshot(exclude=props("realm"))


@pytest.mark.asyncio
async def test_input_performActionsEmitsDragging(websocket, context_id, html,
query_selector, snapshot,
Expand Down
Loading