From 18ee800e378da11021f6d7e930da5e4acfe070e8 Mon Sep 17 00:00:00 2001 From: Randolf Jung Date: Fri, 3 Nov 2023 10:22:36 +0100 Subject: [PATCH] [WebDriver BiDi] Update tilt tests --- .../bidi/input/perform_actions/invalid.py | 40 +------------------ .../bidi/input/perform_actions/pointer_pen.py | 6 +-- .../input/perform_actions/pointer_touch.py | 26 +++++------- .../classic/perform_actions/pointer_pen.py | 6 +-- .../classic/perform_actions/pointer_touch.py | 32 +++++++++++---- 5 files changed, 42 insertions(+), 68 deletions(-) diff --git a/webdriver/tests/bidi/input/perform_actions/invalid.py b/webdriver/tests/bidi/input/perform_actions/invalid.py index 0269a1bc8f32a0..631b3026c1771c 100644 --- a/webdriver/tests/bidi/input/perform_actions/invalid.py +++ b/webdriver/tests/bidi/input/perform_actions/invalid.py @@ -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": @@ -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( diff --git a/webdriver/tests/bidi/input/perform_actions/pointer_pen.py b/webdriver/tests/bidi/input/perform_actions/pointer_pen.py index 04fb24edccd3f3..5cdacbbb489ac3 100644 --- a/webdriver/tests/bidi/input/perform_actions/pointer_pen.py +++ b/webdriver/tests/bidi/input/perform_actions/pointer_pen.py @@ -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=0.2419, 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)) @@ -110,8 +110,8 @@ 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]["tiltX"] == 72 + assert events[3]["tiltY"] == 38 assert events[3]["twist"] == 86 assert events[6]["type"] == "pointermove" assert events[6]["pageX"] == pytest.approx(center["x"] + 10, abs=1.0) diff --git a/webdriver/tests/bidi/input/perform_actions/pointer_touch.py b/webdriver/tests/bidi/input/perform_actions/pointer_touch.py index c1c430765f7dfd..3b91b93487929b 100644 --- a/webdriver/tests/bidi/input/perform_actions/pointer_touch.py +++ b/webdriver/tests/bidi/input/perform_actions/pointer_touch.py @@ -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( @@ -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) @@ -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_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") @@ -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( @@ -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) @@ -195,10 +187,10 @@ 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]["tiltX"] == 20 + assert events[2]["tiltY"] == -6 assert events[2]["twist"] == 355 assert events[3]["type"] == "pointermove" - assert events[3]["tiltX"] == -19 - assert events[3]["tiltY"] == 62 + assert events[3]["tiltX"] == -23 + assert events[3]["tiltY"] == 61 assert events[3]["twist"] == 345 diff --git a/webdriver/tests/classic/perform_actions/pointer_pen.py b/webdriver/tests/classic/perform_actions/pointer_pen.py index fcd1aba9474eb4..b846f7e7ed5935 100644 --- a/webdriver/tests/classic/perform_actions/pointer_pen.py +++ b/webdriver/tests/classic/perform_actions/pointer_pen.py @@ -78,7 +78,7 @@ def test_pen_pointer_properties(session, test_actions_pointer_page, pen_chain): pointerArea = session.find.css("#pointerArea", all=False) center = get_inview_center(pointerArea.rect, get_viewport_rect(session)) pen_chain.pointer_move(0, 0, origin=pointerArea) \ - .pointer_down(pressure=0.36, tilt_x=-72, tilt_y=9, twist=86) \ + .pointer_down(pressure=0.36, altitude_angle=0.3, azimuth_angle=0.2419, twist=86) \ .pointer_move(10, 10, origin=pointerArea) \ .pointer_up() \ .pointer_move(80, 50, origin=pointerArea) \ @@ -98,8 +98,8 @@ def test_pen_pointer_properties(session, test_actions_pointer_page, pen_chain): 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]["tiltX"] == 72 + assert events[3]["tiltY"] == 38 assert events[3]["twist"] == 86 assert events[6]["type"] == "pointermove" assert events[6]["pageX"] == pytest.approx(center["x"]+10, abs=1.0) diff --git a/webdriver/tests/classic/perform_actions/pointer_touch.py b/webdriver/tests/classic/perform_actions/pointer_touch.py index 6c8e2f3fa6e2a9..ab49f1eed6d117 100644 --- a/webdriver/tests/classic/perform_actions/pointer_touch.py +++ b/webdriver/tests/classic/perform_actions/pointer_touch.py @@ -73,8 +73,8 @@ def test_touch_pointer_properties(session, test_actions_pointer_page, touch_chai pointerArea = session.find.css("#pointerArea", all=False) center = get_inview_center(pointerArea.rect, get_viewport_rect(session)) touch_chain.pointer_move(0, 0, origin=pointerArea) \ - .pointer_down(width=23, height=31, pressure=0.78, tilt_x=21, tilt_y=-8, twist=355) \ - .pointer_move(10, 10, origin=pointerArea, width=39, height=35, pressure=0.91, tilt_x=-19, tilt_y=62, twist=345) \ + .pointer_down(width=23, height=31, pressure=0.78, twist=355) \ + .pointer_move(10, 10, origin=pointerArea, width=39, height=35, pressure=0.91, twist=345) \ .pointer_up() \ .pointer_move(80, 50, origin=pointerArea) \ .perform() @@ -101,13 +101,31 @@ def test_touch_pointer_properties(session, test_actions_pointer_page, touch_chai assert round(events[3]["pressure"], 2) == 0.91 +def test_touch_pointer_properties_angle_twist(session, test_actions_pointer_page, touch_chain): + pointerArea = session.find.css("#pointerArea", all=False) + touch_chain.pointer_move(0, 0, origin=pointerArea) \ + .pointer_down(width=23, height=31, pressure=0.78, altitude_angle=1.2, azimuth_angle=6, twist=355) \ + .pointer_move(10, 10, origin=pointerArea, width=39, height=35, pressure=0.91, altitude_angle=0.5, azimuth_angle=1.8, twist=345) \ + .pointer_up() \ + .pointer_move(80, 50, origin=pointerArea) \ + .perform() + events = get_events(session) + assert len(events) == 7 + event_types = [e["type"] for e in events] + assert ["pointerover", "pointerenter", "pointerdown", "pointermove", + "pointerup", "pointerout", "pointerleave"] == event_types + assert events[2]["type"] == "pointerdown" + assert events[2]["tiltX"] == 20 + assert events[2]["tiltY"] == -6 + assert events[2]["twist"] == 355 + assert events[3]["type"] == "pointermove" + assert events[3]["tiltX"] == -23 + assert events[3]["tiltY"] == 61 + assert events[3]["twist"] == 345 + + def test_touch_pointer_properties_tilt_twist(session, test_actions_pointer_page, touch_chain): - # 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 pointerArea = session.find.css("#pointerArea", all=False) - center = get_inview_center(pointerArea.rect, get_viewport_rect(session)) touch_chain.pointer_move(0, 0, origin=pointerArea) \ .pointer_down(width=23, height=31, pressure=0.78, tilt_x=21, tilt_y=-8, twist=355) \ .pointer_move(10, 10, origin=pointerArea, width=39, height=35, pressure=0.91, tilt_x=-19, tilt_y=62, twist=345) \