Bug 1850086 - Make `Actions` compute `buttons` value from `button` value correctly r=webdriver-reviewers,whimboo

`MouseButton.buttons` value for middle button is `4`, and for right button is
`2`.  However, their button values are `1` and `2`.  Therefore, their values
cannot be computed with `Math.pow` simply.

Differential Revision: https://phabricator.services.mozilla.com/D186912
This commit is contained in:
Masayuki Nakano 2023-09-04 07:44:28 +00:00
Родитель 93e972c03d
Коммит e03c6e0960
7 изменённых файлов: 176 добавлений и 45 удалений

Просмотреть файл

@ -1984,7 +1984,26 @@ class PointerEventData extends InputEventData {
this.shiftKey = otherInputSource.shift || this.shiftKey;
}
const allButtons = Array.from(inputSource.pressed);
this.buttons = allButtons.reduce((a, i) => a + Math.pow(2, i), 0);
this.buttons = allButtons.reduce(
(a, i) => a + PointerEventData.getButtonFlag(i),
0
);
}
/**
* Return a flag for buttons which indicates a button is pressed.
*
* @param {integer} button - Mouse button number.
*/
static getButtonFlag(button) {
switch (button) {
case 1:
return 4;
case 2:
return 2;
default:
return Math.pow(2, button);
}
}
}
@ -2093,7 +2112,8 @@ class MultiTouchEventData extends PointerEventData {
// anyway.
const allButtons = Array.from(inputSource.pressed);
this.buttons =
this.buttons | allButtons.reduce((a, i) => a + Math.pow(2, i), 0);
this.buttons |
allButtons.reduce((a, i) => a + PointerEventData.getButtonFlag(i), 0);
}
}

Просмотреть файл

@ -9,47 +9,86 @@
[mouse pointerevent attributes]
expected: NOTRUN
[mouse pointerdown's type should be pointerdown]
expected: FAIL
[mouse pointerup's type should be pointerup]
expected: FAIL
[mouse pointerout's type should be pointerout]
expected: FAIL
[mouse pointerenter.toElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerout.toElement value is null]
expected: PRECONDITION_FAILED
[mouse pointermove.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerout.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerover.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerenter.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerover.toElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerup.toElement value is null]
[mouse pointerenter.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerleave.toElement value is null]
[mouse pointerenter.toElement value is null]
expected: PRECONDITION_FAILED
[mouse pointermove.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointermove.toElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerdown.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerdown.toElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerup.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerup.toElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerout.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerout.toElement value is null]
expected: PRECONDITION_FAILED
[mouse pointerleave.fromElement value is null]
expected: PRECONDITION_FAILED
[mouse pointermove.toElement value is null]
[mouse pointerleave.toElement value is null]
expected: PRECONDITION_FAILED
[Inner frame mouse pointerover's button is -1 when mouse buttons are in released state.]
expected: FAIL
[Inner frame mouse pointerover's buttons is 0 when mouse buttons are in released state.]
expected: FAIL
[Inner frame mouse pointerover.fromElement value is null]
expected: PRECONDITION_FAILED
[Inner frame mouse pointerover.toElement value is null]
expected: PRECONDITION_FAILED
[Inner frame mouse pointerenter's button is -1 when mouse buttons are in released state.]
expected: FAIL
[Inner frame mouse pointerenter's buttons is 0 when mouse buttons are in released state.]
expected: FAIL
[Inner frame mouse pointerenter.fromElement value is null]
expected: PRECONDITION_FAILED
[Inner frame mouse pointerenter.toElement value is null]
expected: PRECONDITION_FAILED
[Inner frame mouse pointermove's type should be pointermove]
expected: FAIL
[Inner frame mouse pointerdown.fromElement value is null]
expected: PRECONDITION_FAILED
[Inner frame mouse pointerdown.toElement value is null]
expected: PRECONDITION_FAILED
[Inner frame mouse pointerdown's type should be pointerdown]
expected: FAIL
[Inner frame mouse pointerup.fromElement value is null]
expected: PRECONDITION_FAILED
[Inner frame mouse pointerup.toElement value is null]
expected: PRECONDITION_FAILED

Просмотреть файл

@ -7,9 +7,8 @@
[pointerevent_auxclick_is_a_pointerevent.html?mouse]
expected: TIMEOUT
[auxclick using mouse is a PointerEvent with correct properties]
expected: TIMEOUT
expected: FAIL
[auxclick using mouse is a PointerEvent with correct properties when no other PointerEvent listeners are present]
expected: NOTRUN
expected: FAIL

Просмотреть файл

@ -13,9 +13,8 @@
[pointerevent_contextmenu_is_a_pointerevent.html?mouse]
expected: TIMEOUT
[contextmenu using mouse is a PointerEvent with correct properties]
expected: TIMEOUT
expected: FAIL
[contextmenu using mouse is a PointerEvent with correct properties when no other PointerEvent listeners are present]
expected: NOTRUN
expected: FAIL

Просмотреть файл

@ -1,5 +1,3 @@
[modifying-selection-with-middle-mouse-button.tentative.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Middle click shouldn't move caret in an editable element if the default of pointerdown event is prevented]
expected: FAIL

Просмотреть файл

@ -80,14 +80,55 @@ async def test_context_menu_at_coordinates(
assert len(events) == 4
expected = [
{"type": "mousedown", "button": 2},
{"type": "contextmenu", "button": 2},
{"type": "mousedown", "button": 2, "buttons": 2},
{"type": "contextmenu", "button": 2, "buttons": 2},
]
# Some browsers in some platforms may dispatch `contextmenu` event as a
# a default action of `mouseup`. In the case, `.buttons` of the event
# should be 0.
anotherExpected = [
{"type": "mousedown", "button": 2, "buttons": 2},
{"type": "contextmenu", "button": 2, "buttons": 0},
]
filtered_events = [filter_dict(e, expected[0]) for e in events]
mousedown_contextmenu_events = [
x for x in filtered_events if x["type"] in ["mousedown", "contextmenu"]
]
assert expected == mousedown_contextmenu_events
assert mousedown_contextmenu_events in [expected, anotherExpected]
async def test_middle_click(bidi_session, top_context, load_static_test_page):
await load_static_test_page(page="test_actions.html")
div_point = {
"x": 82,
"y": 187,
}
actions = Actions()
(
actions.add_pointer()
.pointer_move(x=div_point["x"], y=div_point["y"])
.pointer_down(button=1)
.pointer_up(button=1)
)
await bidi_session.input.perform_actions(
actions=actions, context=top_context["context"]
)
events = await get_events(bidi_session, top_context["context"])
assert len(events) == 3
expected = [
{"type": "mousedown", "button": 1, "buttons": 4},
{"type": "mouseup", "button": 1, "buttons": 0},
]
filtered_events = [filter_dict(e, expected[0]) for e in events]
mousedown_mouseup_events = [
x for x in filtered_events if x["type"] in ["mousedown", "mouseup"]
]
assert expected == mousedown_mouseup_events
async def test_click_element_center(

Просмотреть файл

@ -74,18 +74,53 @@ def test_context_menu_at_coordinates(session, test_actions_page, mouse_chain):
.pointer_down(button=2) \
.pointer_up(button=2) \
.perform()
events = get_events(session)
expected = [
{"type": "mousedown", "button": 2},
{"type": "contextmenu", "button": 2},
]
assert len(events) == 4
expected = [
{"type": "mousedown", "button": 2, "buttons": 2},
{"type": "contextmenu", "button": 2, "buttons": 2},
]
# Some browsers in some platforms may dispatch `contextmenu` event as a
# a default action of `mouseup`. In the case, `.buttons` of the event
# should be 0.
anotherExpected = [
{"type": "mousedown", "button": 2, "buttons": 2},
{"type": "contextmenu", "button": 2, "buttons": 0},
]
filtered_events = [filter_dict(e, expected[0]) for e in events]
mousedown_contextmenu_events = [
x for x in filtered_events
if x["type"] in ["mousedown", "contextmenu"]
]
assert expected == mousedown_contextmenu_events
assert mousedown_contextmenu_events in [expected, anotherExpected]
def test_middle_click(session, test_actions_page, mouse_chain):
div_point = {
"x": 82,
"y": 187,
}
mouse_chain \
.pointer_move(div_point["x"], div_point["y"]) \
.pointer_down(button=1) \
.pointer_up(button=1) \
.perform()
events = get_events(session)
assert len(events) == 3
expected = [
{"type": "mousedown", "button": 1, "buttons": 4},
{"type": "mouseup", "button": 1, "buttons": 0},
]
filtered_events = [filter_dict(e, expected[0]) for e in events]
mousedown_mouseup_events = [
x for x in filtered_events
if x["type"] in ["mousedown", "mouseup"]
]
assert expected == mousedown_mouseup_events
def test_click_element_center(session, test_actions_page, mouse_chain):