Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / actions / mouse_dblclick.py
1 import pytest
2
3 from tests.actions.support.mouse import get_center
4 from tests.actions.support.refine import get_events, filter_dict
5 from tests.support.asserts import assert_move_to_coordinates
6
7
8 _DBLCLICK_INTERVAL = 640
9
10
11 # Using local fixtures because we want to start a new session between
12 # each test, otherwise the clicks in each test interfere with each other.
13 @pytest.fixture(autouse=True)
14 def release_actions(dblclick_session, request):
15     # release all actions after each test
16     # equivalent to a teardown_function, but with access to session fixture
17     request.addfinalizer(dblclick_session.actions.release)
18
19
20 @pytest.fixture
21 def dblclick_session(new_session, url, add_browser_capabilites):
22     _, session = new_session({"capabilities": {"alwaysMatch": add_browser_capabilites({})}})
23     session.url = url("/webdriver/tests/actions/support/test_actions_wdspec.html")
24
25     return session
26
27
28 @pytest.fixture
29 def mouse_chain(dblclick_session):
30     return dblclick_session.actions.sequence(
31         "pointer",
32         "pointer_id",
33         {"pointerType": "mouse"})
34
35
36 @pytest.mark.parametrize("click_pause", [0, 200])
37 def test_dblclick_at_coordinates(dblclick_session, mouse_chain, click_pause):
38     div_point = {
39         "x": 82,
40         "y": 187,
41     }
42     mouse_chain \
43         .pointer_move(div_point["x"], div_point["y"]) \
44         .click() \
45         .pause(click_pause) \
46         .click() \
47         .perform()
48     events = get_events(dblclick_session)
49     assert_move_to_coordinates(div_point, "outer", events)
50     expected = [
51         {"type": "mousedown", "button": 0},
52         {"type": "mouseup", "button": 0},
53         {"type": "click", "button": 0},
54         {"type": "mousedown", "button": 0},
55         {"type": "mouseup", "button": 0},
56         {"type": "click", "button": 0},
57         {"type": "dblclick", "button": 0},
58     ]
59     assert len(events) == 8
60     filtered_events = [filter_dict(e, expected[0]) for e in events]
61     assert expected == filtered_events[1:]
62
63
64 def test_dblclick_with_pause_after_second_pointerdown(dblclick_session, mouse_chain):
65         outer = dblclick_session.find.css("#outer", all=False)
66         center = get_center(outer.rect)
67         mouse_chain \
68             .pointer_move(int(center["x"]), int(center["y"])) \
69             .click() \
70             .pointer_down() \
71             .pause(_DBLCLICK_INTERVAL + 10) \
72             .pointer_up() \
73             .perform()
74         events = get_events(dblclick_session)
75         expected = [
76             {"type": "mousedown", "button": 0},
77             {"type": "mouseup", "button": 0},
78             {"type": "click", "button": 0},
79             {"type": "mousedown", "button": 0},
80             {"type": "mouseup", "button": 0},
81             {"type": "click", "button": 0},
82             {"type": "dblclick", "button": 0},
83         ]
84         assert len(events) == 8
85         filtered_events = [filter_dict(e, expected[0]) for e in events]
86         assert expected == filtered_events[1:]
87
88
89 def test_no_dblclick(dblclick_session, mouse_chain):
90         outer = dblclick_session.find.css("#outer", all=False)
91         center = get_center(outer.rect)
92         mouse_chain \
93             .pointer_move(int(center["x"]), int(center["y"])) \
94             .click() \
95             .pause(_DBLCLICK_INTERVAL + 10) \
96             .click() \
97             .perform()
98         events = get_events(dblclick_session)
99         expected = [
100             {"type": "mousedown", "button": 0},
101             {"type": "mouseup", "button": 0},
102             {"type": "click", "button": 0},
103             {"type": "mousedown", "button": 0},
104             {"type": "mouseup", "button": 0},
105             {"type": "click", "button": 0},
106         ]
107         assert len(events) == 7
108         filtered_events = [filter_dict(e, expected[0]) for e in events]
109         assert expected == filtered_events[1:]