Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / actions / sequence.py
1 # META: timeout=long
2
3 from tests.actions.support.refine import get_keys, filter_dict, get_events
4 from tests.actions.support.keys import Keys
5
6
7 def test_no_actions_send_no_events(session, key_reporter, key_chain):
8     key_chain.perform()
9     assert len(get_keys(key_reporter)) == 0
10     assert len(get_events(session)) == 0
11
12
13 def test_release_char_sequence_sends_keyup_events_in_reverse(session,
14                                                              key_reporter,
15                                                              key_chain):
16     key_chain \
17         .key_down("a") \
18         .key_down("b") \
19         .perform()
20     # reset so we only see the release events
21     session.execute_script("resetEvents();")
22     session.actions.release()
23     expected = [
24         {"code": "KeyB", "key": "b", "type": "keyup"},
25         {"code": "KeyA", "key": "a", "type": "keyup"},
26     ]
27     all_events = get_events(session)
28     events = [filter_dict(e, expected[0]) for e in all_events]
29     if len(events) > 0 and events[0]["code"] == None:
30         # Remove 'code' entry if browser doesn't support it
31         expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
32         events = [filter_dict(e, expected[0]) for e in events]
33     assert events == expected
34
35
36 def test_release_no_actions_sends_no_events(session, key_reporter):
37     session.actions.release()
38     assert len(get_keys(key_reporter)) == 0
39     assert len(get_events(session)) == 0
40
41
42 def test_many_modifiers_click(session, test_actions_page, key_chain, mouse_chain):
43     outer = session.find.css("#outer", all=False)
44     key_chain \
45         .pause(0) \
46         .key_down(Keys.CONTROL) \
47         .key_down(Keys.SHIFT) \
48         .pause(0) \
49         .key_up(Keys.CONTROL) \
50         .key_up(Keys.SHIFT)
51     mouse_chain \
52         .pointer_move(0, 0, origin=outer) \
53         .pause(0) \
54         .pointer_down() \
55         .pointer_up() \
56         .pause(0) \
57         .pause(0) \
58         .pointer_down()
59     session.actions.perform([key_chain.dict, mouse_chain.dict])
60     expected = [
61         {"type": "mousemove"},
62         # shift and ctrl presses
63         {"type": "mousedown"},
64         {"type": "mouseup"},
65         {"type": "click"},
66         # no modifiers pressed
67         {"type": "mousedown"},
68     ]
69     defaults = {
70         "altKey": False,
71         "metaKey": False,
72         "shiftKey": False,
73         "ctrlKey": False
74     }
75     for e in expected:
76         e.update(defaults)
77     for e in expected[1:4]:
78         e["shiftKey"] = True
79         e["ctrlKey"] = True
80     events = [filter_dict(e, expected[0]) for e in get_events(session)]
81     assert events == expected