Example #1
0
def test_drag_and_drop(session,
                       test_actions_page,
                       mouse_chain,
                       dx,
                       dy,
                       drag_duration):
    drag_target = session.find.css("#dragTarget", all=False)
    initial_rect = drag_target.rect
    initial_center = get_inview_center(initial_rect, get_viewport_rect(session))
    # Conclude chain with extra move to allow time for last queued
    # coordinate-update of drag_target and to test that drag_target is "dropped".
    mouse_chain \
        .pointer_move(0, 0, origin=drag_target) \
        .pointer_down() \
        .pointer_move(dx, dy, duration=drag_duration, origin="pointer") \
        .pointer_up() \
        .pointer_move(80, 50, duration=100, origin="pointer") \
        .perform()
    # mouseup that ends the drag is at the expected destination
    e = get_events(session)[1]
    assert e["type"] == "mouseup"
    assert pytest.approx(e["pageX"], initial_center["x"] + dx)
    assert pytest.approx(e["pageY"], initial_center["y"] + dy)
    # check resulting location of the dragged element
    final_rect = drag_target.rect
    assert initial_rect["x"] + dx == final_rect["x"]
    assert initial_rect["y"] + dy == final_rect["y"]
Example #2
0
def test_element_center_point_with_offset(session, mouse_chain):
    session.url = origin_doc("width: 100px; height: 50px; background: green;")
    elem = session.find.css("#inner", all=False)
    center = get_inview_center(elem.rect, get_viewport_rect(session))

    mouse_chain \
        .pointer_move(10, 15, origin=elem) \
        .perform()

    click_coords = get_click_coordinates(session)
    assert pytest.approx(click_coords["x"], center["x"] + 10)
    assert pytest.approx(click_coords["y"], center["y"] + 15)
Example #3
0
def test_element_larger_than_viewport(session, mouse_chain):
    session.url = origin_doc("width: 300vw; height: 300vh; background: green;")
    elem = session.find.css("#inner", all=False)
    center = get_inview_center(elem.rect, get_viewport_rect(session))

    mouse_chain \
        .pointer_move(0, 0, origin=elem) \
        .perform()

    click_coords = get_click_coordinates(session)
    assert pytest.approx(click_coords["x"], center["x"])
    assert pytest.approx(click_coords["y"], center["y"])
Example #4
0
def test_click_element_center(session, test_actions_page, mouse_chain):
    outer = session.find.css("#outer", all=False)
    center = get_inview_center(outer.rect, get_viewport_rect(session))
    mouse_chain.click(element=outer).perform()
    events = get_events(session)
    assert len(events) == 4
    event_types = [e["type"] for e in events]
    assert ["mousemove", "mousedown", "mouseup", "click"] == event_types
    for e in events:
        if e["type"] != "mousemove":
            assert pytest.approx(e["pageX"], center["x"])
            assert pytest.approx(e["pageY"], center["y"])
            assert e["target"] == "outer"
Example #5
0
File: mouse.py Project: sw811/wpt
def test_click_element_center(session, test_actions_page, mouse_chain):
    outer = session.find.css("#outer", all=False)
    center = get_inview_center(outer.rect, get_viewport_rect(session))
    mouse_chain.click(element=outer).perform()
    events = get_events(session)
    assert len(events) == 4
    event_types = [e["type"] for e in events]
    assert ["mousemove", "mousedown", "mouseup", "click"] == event_types
    for e in events:
        if e["type"] != "mousemove":
            assert pytest.approx(e["pageX"], center["x"])
            assert pytest.approx(e["pageY"], center["y"])
            assert e["target"] == "outer"
Example #6
0
def test_element_in_view_center_point_partly_visible(session, mouse_chain):
    session.url = origin_doc("""width: 100px; height: 50px; background: green;
                                position: relative; left: -50px; top: -25px;"""
                             )
    elem = session.find.css("#inner", all=False)
    center = get_inview_center(elem.rect, get_viewport_rect(session))

    mouse_chain \
        .pointer_move(0, 0, origin=elem) \
        .perform()

    click_coords = get_click_coordinates(session)
    assert pytest.approx(click_coords["x"], center["x"])
    assert pytest.approx(click_coords["y"], center["y"])
def test_dblclick_with_pause_after_second_pointerdown(session,
                                                      test_actions_page,
                                                      mouse_chain):
    outer = session.find.css("#outer", all=False)
    center = get_inview_center(outer.rect, get_viewport_rect(session))
    mouse_chain \
        .pointer_move(int(center["x"]), int(center["y"])) \
        .click() \
        .pointer_down() \
        .pause(_DBLCLICK_INTERVAL + 10) \
        .pointer_up() \
        .perform()
    events = get_events(session)
    expected = [
        {
            "type": "mousedown",
            "button": 0
        },
        {
            "type": "mouseup",
            "button": 0
        },
        {
            "type": "click",
            "button": 0
        },
        {
            "type": "mousedown",
            "button": 0
        },
        {
            "type": "mouseup",
            "button": 0
        },
        {
            "type": "click",
            "button": 0
        },
        {
            "type": "dblclick",
            "button": 0
        },
    ]
    assert len(events) == 8
    filtered_events = [filter_dict(e, expected[0]) for e in events]
    assert expected == filtered_events[1:]
def test_no_dblclick(session, test_actions_page, mouse_chain):
        outer = session.find.css("#outer", all=False)
        center = get_inview_center(outer.rect, get_viewport_rect(session))
        mouse_chain \
            .pointer_move(int(center["x"]), int(center["y"])) \
            .click() \
            .pause(_DBLCLICK_INTERVAL + 10) \
            .click() \
            .perform()
        events = get_events(session)
        expected = [
            {"type": "mousedown", "button": 0},
            {"type": "mouseup", "button": 0},
            {"type": "click", "button": 0},
            {"type": "mousedown", "button": 0},
            {"type": "mouseup", "button": 0},
            {"type": "click", "button": 0},
        ]
        assert len(events) == 7
        filtered_events = [filter_dict(e, expected[0]) for e in events]
        assert expected == filtered_events[1:]
Example #9
0
File: mouse.py Project: sw811/wpt
def test_drag_and_drop(session, test_actions_page, mouse_chain, dx, dy,
                       drag_duration):
    drag_target = session.find.css("#dragTarget", all=False)
    initial_rect = drag_target.rect
    initial_center = get_inview_center(initial_rect,
                                       get_viewport_rect(session))
    # Conclude chain with extra move to allow time for last queued
    # coordinate-update of drag_target and to test that drag_target is "dropped".
    mouse_chain \
        .pointer_move(0, 0, origin=drag_target) \
        .pointer_down() \
        .pointer_move(dx, dy, duration=drag_duration, origin="pointer") \
        .pointer_up() \
        .pointer_move(80, 50, duration=100, origin="pointer") \
        .perform()
    # mouseup that ends the drag is at the expected destination
    e = get_events(session)[1]
    assert e["type"] == "mouseup"
    assert pytest.approx(e["pageX"], initial_center["x"] + dx)
    assert pytest.approx(e["pageY"], initial_center["y"] + dy)
    # check resulting location of the dragged element
    final_rect = drag_target.rect
    assert initial_rect["x"] + dx == final_rect["x"]
    assert initial_rect["y"] + dy == final_rect["y"]