Repository: servo/servo
File: tests/wpt/tests/webdriver/tests/classic/perform_actions/pointer_touch.py (Python)

Code before:
        window.events = {
            touchstart: false,
            touchcancel: false,
            touchend: false,
            click: false
        };
        const area = document.getElementById("pointerArea");
        ['touchstart', 'touchcancel', 'touchend', 'click'].forEach(type => {
            area.addEventListener(type, () => { window.events[type] = true; });
        });
    """)

    touch_chain.pointer_move(0, 0, origin=pointerArea) \
        .pointer_down() \
        .pointer_cancel() \
        .pointer_up() \
        .perform()

    # Use delay to allow potential
    # simulated click to spin (which should not if pointerCancel works)
    time.sleep(1)
    results = session.execute_script("return window.events;")

    assert results['touchstart']
    assert results["touchcancel"]
    assert not results["touchend"]
    assert not results["click"]


@pytest.mark.parametrize("as_frame", [False, True], ids=["top_context", "child_context"])
def test_stale_element_reference(session, stale_element, touch_chain, as_frame):
    element = stale_element("input#text", as_frame=as_frame)

    with pytest.raises(StaleElementReferenceException):
        touch_chain.click(element=element).perform()


@pytest.mark.parametrize("origin", ["element", "pointer", "viewport"])
def test_params_actions_origin_outside_viewport(session, test_actions_page, touch_chain, origin):
    if origin == "element":
        origin = session.find.css("#outer", all=False)

    with pytest.raises(MoveTargetOutOfBoundsException):
        touch_chain.pointer_move(-100, -100, origin=origin).perform()


def test_move_to_fractional_position(session, inline, touch_chain):
    session.url = inline("""
        <script>
          var allEvents = { events: [] };
          window.addEventListener("pointermove", ev => {

Review comment (suggestion):
```suggestion
    assert results["touchend"]
```
This should be true instead, as we removed the touch point with `pointer_up`:
https://w3c.github.io/touch-events/#dfn-touchend

Code after:
        window.events = {
            touchstart: false,
            touchcancel: false,
            touchend: false,
            click: false
        };
        const area = document.getElementById("pointerArea");
        ['touchstart', 'touchcancel', 'touchend', 'click'].forEach(type => {
            area.addEventListener(type, () => { window.events[type] = true; });
        });
    """)

    touch_chain.pointer_move(0, 0, origin=pointerArea) \
        .pointer_down() \
        .pointer_cancel() \
        .pointer_up() \
        .perform()

    # Use delay to allow potential
    # simulated click to spin (which should not if pointerCancel works)
    time.sleep(1)
    results = session.execute_script("return window.events;")

    assert results['touchstart']
    assert results["touchcancel"]
    assert results["touchend"]
    assert not results["click"]


def test_touch_pointer_cancel_without_up(session, test_actions_pointer_page, touch_chain):
    pointerArea = session.find.css("#pointerArea", all=False)

    session.execute_script("""
        window.events = {
            touchstart: false,
            touchcancel: false,
            touchend: false,
            click: false
        };
        const area = document.getElementById("pointerArea");
        ['touchstart', 'touchcancel', 'touchend', 'click'].forEach(type => {
            area.addEventListener(type, () => { window.events[type] = true; });
        });
    """)

    touch_chain.pointer_move(0, 0, origin=pointerArea) \
        .pointer_down() \
        .pointer_cancel() \
        .perform()

    # Use delay to allow potential