Skip to content

Commit

Permalink
[wdspec] Fix WebDriver classic and BiDi drag and drop position tests.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D232725

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1871346
gecko-commit: d13caad2c6161773f359021d3ebe132880d93bf6
gecko-reviewers: webdriver-reviewers, Sasha
  • Loading branch information
whimboo authored and moz-wptsync-bot committed Dec 22, 2024
1 parent 4e14309 commit 099359f
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 74 deletions.
24 changes: 21 additions & 3 deletions webdriver/tests/bidi/input/perform_actions/pointer_mouse_drag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from webdriver.bidi.modules.input import Actions, get_element_origin

from tests.support.sync import AsyncPoll
from .. import get_events
from . import get_element_rect, get_inview_center_bidi

Expand Down Expand Up @@ -56,10 +57,27 @@ async def test_drag_and_drop(
assert e["pageX"] == pytest.approx(initial_center["x"] + dx, abs=1.0)
assert e["pageY"] == pytest.approx(initial_center["y"] + dy, abs=1.0)

final_rect = None

async def check_final_position(_):
nonlocal final_rect

final_rect = await get_element_rect(
bidi_session, context=top_context, element=drag_target
)
return (
final_rect["x"] == pytest.approx(
initial_rect["x"] + dx, abs=1.0) and
final_rect["y"] == pytest.approx(
initial_rect["y"] + dy, abs=1.0)

)

wait = AsyncPoll(
bidi_session, message="""Dragged element did not reach target position""")
await wait.until(check_final_position)

# check resulting location of the dragged element
final_rect = await get_element_rect(
bidi_session, context=top_context, element=drag_target
)
assert final_rect["x"] == pytest.approx(initial_rect["x"] + dx, abs=1.0)
assert final_rect["y"] == pytest.approx(initial_rect["y"] + dy, abs=1.0)

Expand Down
71 changes: 0 additions & 71 deletions webdriver/tests/classic/perform_actions/pointer_mouse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from webdriver.error import (
InvalidArgumentException,
MoveTargetOutOfBoundsException,
Expand Down Expand Up @@ -280,76 +279,6 @@ def test_move_to_origin_position_within_frame(
assert events[0] == target_point


@pytest.mark.parametrize("drag_duration", [0, 300, 800])
@pytest.mark.parametrize("dx, dy", [
(20, 0), (0, 15), (10, 15), (-20, 0), (10, -15), (-10, -15)
])
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 e["pageX"] == pytest.approx(initial_center["x"] + dx, abs=1.0)
assert e["pageY"] == pytest.approx(initial_center["y"] + dy, abs=1.0)

# check resulting location of the dragged element
final_rect = drag_target.rect
assert final_rect["x"] == pytest.approx(initial_rect["x"] + dx, abs=1.0)
assert final_rect["y"] == pytest.approx(initial_rect["y"] + dy, abs=1.0)


@pytest.mark.parametrize("drag_duration", [0, 300, 800])
def test_drag_and_drop_with_draggable_element(session_new_window,
test_actions_page,
mouse_chain,
drag_duration):
new_session = session_new_window
drag_target = new_session.find.css("#draggable", all=False)
drop_target = new_session.find.css("#droppable", all=False)
# 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(50,
25,
duration=drag_duration,
origin=drop_target) \
.pointer_up() \
.pointer_move(80, 50, duration=100, origin="pointer") \
.perform()
# mouseup that ends the drag is at the expected destination
e = get_events(new_session)
assert len(e) >= 5
assert e[1]["type"] == "dragstart", "Events captured were {}".format(e)
assert e[2]["type"] == "dragover", "Events captured were {}".format(e)
drag_events_captured = [
ev["type"] for ev in e if ev["type"].startswith("drag") or ev["type"].startswith("drop")
]
assert "dragend" in drag_events_captured
assert "dragenter" in drag_events_captured
assert "dragleave" in drag_events_captured
assert "drop" in drag_events_captured


@pytest.mark.parametrize("missing", ["x", "y"])
def test_missing_coordinates(session, test_actions_page, mouse_chain, missing):
outer = session.find.css("#outer", all=False)
Expand Down
97 changes: 97 additions & 0 deletions webdriver/tests/classic/perform_actions/pointer_mouse_drag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import pytest

from tests.classic.perform_actions.support.mouse import (
get_inview_center,
get_viewport_rect,
)
from tests.classic.perform_actions.support.refine import get_events
from tests.support.sync import Poll


@pytest.mark.parametrize("drag_duration", [0, 300, 800])
@pytest.mark.parametrize("dx, dy", [
(20, 0), (0, 15), (10, 15), (-20, 0), (10, -15), (-10, -15)
])
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 e["pageX"] == pytest.approx(initial_center["x"] + dx, abs=1.0)
assert e["pageY"] == pytest.approx(initial_center["y"] + dy, abs=1.0)

final_rect = None

def check_final_position(_):
nonlocal final_rect

final_rect = drag_target.rect
return (
final_rect["x"] == pytest.approx(
initial_rect["x"] + dx, abs=1.0) and
final_rect["y"] == pytest.approx(
initial_rect["y"] + dy, abs=1.0)

)

wait = Poll(
session, message="""Dragged element did not reach target position""")
wait.until(check_final_position)

assert final_rect["x"] == pytest.approx(
initial_rect["x"] + dx, abs=1.0)
assert final_rect["y"] == pytest.approx(
initial_rect["y"] + dy, abs=1.0)


@pytest.mark.parametrize("drag_duration", [0, 300, 800])
def test_drag_and_drop_with_draggable_element(session_new_window,
test_actions_page,
mouse_chain,
drag_duration):
new_session = session_new_window
drag_target = new_session.find.css("#draggable", all=False)
drop_target = new_session.find.css("#droppable", all=False)
# 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(50,
25,
duration=drag_duration,
origin=drop_target) \
.pointer_up() \
.pointer_move(80, 50, duration=100, origin="pointer") \
.perform()
# mouseup that ends the drag is at the expected destination
e = get_events(new_session)
assert len(e) >= 5
assert e[1]["type"] == "dragstart", "Events captured were {}".format(e)
assert e[2]["type"] == "dragover", "Events captured were {}".format(e)
drag_events_captured = [
ev["type"] for ev in e if ev["type"].startswith("drag") or ev["type"].startswith("drop")
]
assert "dragend" in drag_events_captured
assert "dragenter" in drag_events_captured
assert "dragleave" in drag_events_captured
assert "drop" in drag_events_captured

0 comments on commit 099359f

Please sign in to comment.