Skip to content

Commit

Permalink
[WebDriver BiDi] Update tilt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf-2 committed Oct 5, 2023
1 parent 34e7f76 commit 1d99619
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 56 deletions.
40 changes: 2 additions & 38 deletions webdriver/tests/bidi/input/perform_actions/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def create_pointer_action(pointer_action, overrides=None, removals=None):
"pressure": 0.0,
"tangentialPressure": 0.0,
"twist": 0,
"tiltX": 0,
"tiltY": 0,
"altitudeAngle": 0,
"azimuthAngle": 0,
}

if pointer_action == "pointerMove":
Expand Down Expand Up @@ -574,42 +574,6 @@ async def test_params_pointer_action_common_properties_angle_invalid_type(
await perform_actions([{"type": "pointer", "id": "foo", "actions": [action]}])


@pytest.mark.parametrize("pointer_action", ["pointerDown", "pointerMove", "pointerUp"])
@pytest.mark.parametrize("tilt", ["tiltX", "tiltY"])
@pytest.mark.parametrize("value", [None, "foo", True, 0.1, [], {}])
async def test_params_pointer_action_common_properties_tilt_invalid_type(
perform_actions, pointer_action, tilt, value
):
action = create_pointer_action(
pointer_action,
{
"tiltX": value if tilt == "tiltX" else 0,
"tiltY": value if tilt == "tiltY" else 0,
},
)

with pytest.raises(InvalidArgumentException):
await perform_actions([{"type": "pointer", "id": "foo", "actions": [action]}])


@pytest.mark.parametrize("pointer_action", ["pointerDown", "pointerMove", "pointerUp"])
@pytest.mark.parametrize("tilt", ["tiltX", "tiltY"])
@pytest.mark.parametrize("value", [-91, 91])
async def test_params_pointer_action_common_properties_tilt_invalid_value(
perform_actions, pointer_action, tilt, value
):
action = create_pointer_action(
pointer_action,
{
"tiltX": value if tilt == "tiltX" else 0,
"tiltY": value if tilt == "tiltY" else 0,
},
)

with pytest.raises(InvalidArgumentException):
await perform_actions([{"type": "pointer", "id": "foo", "actions": [action]}])


@pytest.mark.parametrize("coordinate", ["x", "y"])
@pytest.mark.parametrize("value", [None, "foo", True, 0.1, [], {}])
async def test_params_wheel_action_scroll_coordinate_invalid_type(
Expand Down
8 changes: 5 additions & 3 deletions webdriver/tests/bidi/input/perform_actions/pointer_pen.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def test_pen_pointer_properties(
(
actions.add_pointer(pointer_type="pen")
.pointer_move(x=0, y=0, origin=get_element_origin(pointerArea))
.pointer_down(button=0, pressure=0.36, tilt_x=-72, tilt_y=9, twist=86)
.pointer_down(button=0, pressure=0.36, altitude_angle=0.3, azimuth_angle=3, twist=86)
.pointer_move(x=10, y=10, origin=get_element_origin(pointerArea))
.pointer_up(button=0)
.pointer_move(x=80, y=50, origin=get_element_origin(pointerArea))
Expand Down Expand Up @@ -110,8 +110,10 @@ async def test_pen_pointer_properties(
assert round(events[3]["width"], 2) == 1
assert round(events[3]["height"], 2) == 1
assert round(events[3]["pressure"], 2) == 0.36
assert events[3]["tiltX"] == -72
assert events[3]["tiltY"] == 9
assert events[3]["altitudeAngle"] == 0.3
assert events[3]["azimuthAngle"] == 3
assert events[3]["tiltX"] == -72.64789490234972
assert events[3]["tiltY"] == 24.522595985029376
assert events[3]["twist"] == 86
assert events[6]["type"] == "pointermove"
assert events[6]["pageX"] == pytest.approx(center["x"] + 10, abs=1.0)
Expand Down
26 changes: 11 additions & 15 deletions webdriver/tests/bidi/input/perform_actions/pointer_touch.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ async def test_touch_pointer_properties(
width=23,
height=31,
pressure=0.78,
tilt_x=21,
tilt_y=-8,
twist=355,
)
.pointer_move(
Expand All @@ -92,8 +90,6 @@ async def test_touch_pointer_properties(
width=39,
height=35,
pressure=0.91,
tilt_x=-19,
tilt_y=62,
twist=345,
)
.pointer_up(button=0)
Expand Down Expand Up @@ -135,13 +131,9 @@ async def test_touch_pointer_properties(
assert round(events[3]["pressure"], 2) == 0.91


async def test_touch_pointer_properties_tilt_twist(
async def test_touch_pointer_properties_angle_tilt_twist(
bidi_session, top_context, get_element, load_static_test_page
):
# This test only covers the tilt/twist properties which are
# more specific to pen-type pointers, but which the spec allows
# for generic touch pointers. Seperating this out gives better
# coverage of the basic properties in test_touch_pointer_properties
await load_static_test_page(page="test_actions_pointer.html")

pointerArea = await get_element("#pointerArea")
Expand All @@ -158,8 +150,8 @@ async def test_touch_pointer_properties_tilt_twist(
width=23,
height=31,
pressure=0.78,
tilt_x=21,
tilt_y=-8,
altitude_angle=1.2,
azimuth_angle=6,
twist=355,
)
.pointer_move(
Expand All @@ -169,8 +161,8 @@ async def test_touch_pointer_properties_tilt_twist(
width=39,
height=35,
pressure=0.91,
tilt_x=-19,
tilt_y=62,
altitude_angle=0.5,
azimuth_angle=1.8,
twist=345,
)
.pointer_up(button=0)
Expand All @@ -195,10 +187,14 @@ async def test_touch_pointer_properties_tilt_twist(
"pointerleave",
] == event_types
assert events[2]["type"] == "pointerdown"
assert events[2]["tiltX"] == 21
assert events[2]["tiltY"] == -8
assert events[2]["altitudeAngle"] == 1.2
assert events[2]["azimuthAngle"] == 6
assert events[2]["tiltX"] == 20.47033124113985
assert events[2]["tiltY"] == -6.199788932725595
assert events[2]["twist"] == 355
assert events[3]["type"] == "pointermove"
assert events[3]["altitudeAngle"] == -22.581969063350815
assert events[3]["azimuthAngle"] == 60.708739804128804
assert events[3]["tiltX"] == -19
assert events[3]["tiltY"] == 62
assert events[3]["twist"] == 345

0 comments on commit 1d99619

Please sign in to comment.