mirror of
https://github.com/servo/servo.git
synced 2025-08-15 02:15:33 +01:00
Update web-platform-tests to revision 1e4fe87a7f01c0b5c614c8f601ffa68b4a00662a
This commit is contained in:
parent
4c3f1756da
commit
432648745e
164 changed files with 8354 additions and 595 deletions
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from tests.actions.support.mouse import get_center
|
||||
from tests.actions.support.mouse import get_inview_center, get_viewport_rect
|
||||
from tests.actions.support.refine import get_events, filter_dict
|
||||
from tests.support.asserts import assert_move_to_coordinates
|
||||
from tests.support.inline import inline
|
||||
|
@ -12,11 +12,6 @@ def link_doc(dest):
|
|||
return inline(content)
|
||||
|
||||
|
||||
# TODO use pytest.approx once we upgrade to pytest > 3.0
|
||||
def approx(n, m, tolerance=1):
|
||||
return abs(n - m) <= tolerance
|
||||
|
||||
|
||||
def test_click_at_coordinates(session, test_actions_page, mouse_chain):
|
||||
div_point = {
|
||||
"x": 82,
|
||||
|
@ -35,7 +30,7 @@ def test_click_at_coordinates(session, test_actions_page, mouse_chain):
|
|||
assert e["button"] == 0
|
||||
expected = [
|
||||
{"type": "mousedown", "buttons": 1},
|
||||
{"type": "mouseup", "buttons": 0},
|
||||
{"type": "mouseup", "buttons": 0},
|
||||
{"type": "click", "buttons": 0},
|
||||
]
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in events]
|
||||
|
@ -55,7 +50,7 @@ def test_context_menu_at_coordinates(session, test_actions_page, mouse_chain):
|
|||
events = get_events(session)
|
||||
expected = [
|
||||
{"type": "mousedown", "button": 2},
|
||||
{"type": "contextmenu", "button": 2},
|
||||
{"type": "contextmenu", "button": 2},
|
||||
]
|
||||
assert len(events) == 4
|
||||
filtered_events = [filter_dict(e, expected[0]) for e in events]
|
||||
|
@ -68,7 +63,7 @@ def test_context_menu_at_coordinates(session, test_actions_page, mouse_chain):
|
|||
|
||||
def test_click_element_center(session, test_actions_page, mouse_chain):
|
||||
outer = session.find.css("#outer", all=False)
|
||||
center = get_center(outer.rect)
|
||||
center = get_inview_center(outer.rect, get_viewport_rect(session))
|
||||
mouse_chain.click(element=outer).perform()
|
||||
events = get_events(session)
|
||||
assert len(events) == 4
|
||||
|
@ -76,8 +71,8 @@ def test_click_element_center(session, test_actions_page, mouse_chain):
|
|||
assert ["mousemove", "mousedown", "mouseup", "click"] == event_types
|
||||
for e in events:
|
||||
if e["type"] != "mousemove":
|
||||
assert approx(e["pageX"], center["x"])
|
||||
assert approx(e["pageY"], center["y"])
|
||||
assert pytest.approx(e["pageX"], center["x"])
|
||||
assert pytest.approx(e["pageY"], center["y"])
|
||||
assert e["target"] == "outer"
|
||||
|
||||
|
||||
|
@ -102,8 +97,9 @@ def test_click_navigation(session, url, release_actions):
|
|||
|
||||
|
||||
@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)])
|
||||
@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,
|
||||
|
@ -112,7 +108,7 @@ def test_drag_and_drop(session,
|
|||
drag_duration):
|
||||
drag_target = session.find.css("#dragTarget", all=False)
|
||||
initial_rect = drag_target.rect
|
||||
initial_center = get_center(initial_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 \
|
||||
|
@ -125,8 +121,8 @@ def test_drag_and_drop(session,
|
|||
# mouseup that ends the drag is at the expected destination
|
||||
e = get_events(session)[1]
|
||||
assert e["type"] == "mouseup"
|
||||
assert approx(e["pageX"], initial_center["x"] + dx)
|
||||
assert approx(e["pageY"], initial_center["y"] + dy)
|
||||
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"]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from tests.actions.support.mouse import get_center
|
||||
from tests.actions.support.mouse import get_inview_center, get_viewport_rect
|
||||
from tests.actions.support.refine import get_events, filter_dict
|
||||
from tests.support.asserts import assert_move_to_coordinates
|
||||
|
||||
|
@ -63,7 +63,7 @@ def test_dblclick_at_coordinates(dblclick_session, mouse_chain, click_pause):
|
|||
|
||||
def test_dblclick_with_pause_after_second_pointerdown(dblclick_session, mouse_chain):
|
||||
outer = dblclick_session.find.css("#outer", all=False)
|
||||
center = get_center(outer.rect)
|
||||
center = get_inview_center(outer.rect, get_viewport_rect(dblclick_session))
|
||||
mouse_chain \
|
||||
.pointer_move(int(center["x"]), int(center["y"])) \
|
||||
.click() \
|
||||
|
@ -88,7 +88,7 @@ def test_dblclick_with_pause_after_second_pointerdown(dblclick_session, mouse_ch
|
|||
|
||||
def test_no_dblclick(dblclick_session, mouse_chain):
|
||||
outer = dblclick_session.find.css("#outer", all=False)
|
||||
center = get_center(outer.rect)
|
||||
center = get_inview_center(outer.rect, get_viewport_rect(dblclick_session))
|
||||
mouse_chain \
|
||||
.pointer_move(int(center["x"]), int(center["y"])) \
|
||||
.click() \
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
import pytest
|
||||
|
||||
from webdriver import MoveTargetOutOfBoundsException
|
||||
|
||||
from tests.actions.support.mouse import get_inview_center, get_viewport_rect
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
def origin_doc(inner_style, outer_style=""):
|
||||
return inline("""
|
||||
<div id="outer" style="{1}"
|
||||
onmousemove="window.coords = {{x: event.clientX, y: event.clientY}}">
|
||||
<div id="inner" style="{0}"></div>
|
||||
</div>
|
||||
""".format(inner_style, outer_style))
|
||||
|
||||
|
||||
def get_click_coordinates(session):
|
||||
return session.execute_script("return window.coords;")
|
||||
|
||||
|
||||
def test_viewport_inside(session, mouse_chain):
|
||||
point = {"x": 50, "y": 50}
|
||||
|
||||
session.url = origin_doc("width: 100px; height: 50px; background: green;")
|
||||
mouse_chain \
|
||||
.pointer_move(point["x"], point["y"], origin="viewport") \
|
||||
.perform()
|
||||
|
||||
click_coords = session.execute_script("return window.coords;")
|
||||
assert pytest.approx(click_coords["x"], point["x"])
|
||||
assert pytest.approx(click_coords["y"], point["y"])
|
||||
|
||||
|
||||
def test_viewport_outside(session, mouse_chain):
|
||||
with pytest.raises(MoveTargetOutOfBoundsException):
|
||||
mouse_chain \
|
||||
.pointer_move(-50, -50, origin="viewport") \
|
||||
.perform()
|
||||
|
||||
|
||||
def test_pointer_inside(session, mouse_chain):
|
||||
start_point = {"x": 50, "y": 50}
|
||||
offset = {"x": 10, "y": 5}
|
||||
|
||||
session.url = origin_doc("width: 100px; height: 50px; background: green;")
|
||||
mouse_chain \
|
||||
.pointer_move(start_point["x"], start_point["y"]) \
|
||||
.pointer_move(offset["x"], offset["y"], origin="pointer") \
|
||||
.perform()
|
||||
|
||||
click_coords = session.execute_script("return window.coords;")
|
||||
assert pytest.approx(click_coords["x"], start_point["x"] + offset["x"])
|
||||
assert pytest.approx(click_coords["y"], start_point["y"] + offset["y"])
|
||||
|
||||
|
||||
def test_pointer_outside(session, mouse_chain):
|
||||
with pytest.raises(MoveTargetOutOfBoundsException):
|
||||
mouse_chain \
|
||||
.pointer_move(-50, -50, origin="pointer") \
|
||||
.perform()
|
||||
|
||||
|
||||
def test_element_center_point(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(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_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)
|
||||
|
||||
|
||||
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_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"])
|
||||
|
||||
|
||||
def test_element_outside_of_view_port(session, mouse_chain):
|
||||
session.url = origin_doc("""width: 100px; height: 50px; background: green;
|
||||
position: relative; left: -200px; top: -100px;""")
|
||||
elem = session.find.css("#inner", all=False)
|
||||
|
||||
with pytest.raises(MoveTargetOutOfBoundsException):
|
||||
mouse_chain \
|
||||
.pointer_move(0, 0, origin=elem) \
|
||||
.perform()
|
|
@ -1,5 +1,26 @@
|
|||
def get_center(rect):
|
||||
return {
|
||||
"x": rect["width"] / 2 + rect["x"],
|
||||
"y": rect["height"] / 2 + rect["y"],
|
||||
def get_viewport_rect(session):
|
||||
return session.execute_script("""
|
||||
return {
|
||||
height: window.innerHeight || document.documentElement.clientHeight,
|
||||
width: window.innerWidth || document.documentElement.clientWidth,
|
||||
};
|
||||
""")
|
||||
|
||||
|
||||
def get_inview_center(elem_rect, viewport_rect):
|
||||
x = {
|
||||
"left": max(0, min(elem_rect["x"], elem_rect["x"] + elem_rect["width"])),
|
||||
"right": min(viewport_rect["width"], max(elem_rect["x"],
|
||||
elem_rect["x"] + elem_rect["width"])),
|
||||
}
|
||||
|
||||
y = {
|
||||
"top": max(0, min(elem_rect["y"], elem_rect["y"] + elem_rect["height"])),
|
||||
"bottom": min(viewport_rect["height"], max(elem_rect["y"],
|
||||
elem_rect["y"] + elem_rect["height"])),
|
||||
}
|
||||
|
||||
return {
|
||||
"x": (x["left"] + x["right"]) / 2,
|
||||
"y": (y["top"] + y["bottom"]) / 2,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue