Unreviewed. Update W3C WebDriver imported tests.
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / actions / modifier_click.py
1 # META: timeout=long
2
3 import pytest
4
5 from tests.actions.support.refine import filter_dict, get_events
6 from tests.actions.support.keys import Keys
7
8
9 @pytest.mark.parametrize("modifier, prop", [
10     (Keys.CONTROL, "ctrlKey"),
11     (Keys.ALT, "altKey"),
12     (Keys.META, "metaKey"),
13     (Keys.SHIFT, "shiftKey"),
14     (Keys.R_CONTROL, "ctrlKey"),
15     (Keys.R_ALT, "altKey"),
16     (Keys.R_META, "metaKey"),
17     (Keys.R_SHIFT, "shiftKey"),
18 ])
19 def test_modifier_click(session,
20                        test_actions_page,
21                        key_chain,
22                        mouse_chain,
23                        modifier,
24                        prop):
25     key_chain \
26         .pause(0) \
27         .key_down(modifier) \
28         .pause(200) \
29         .key_up(modifier)
30     outer = session.find.css("#outer", all=False)
31     mouse_chain.click(element=outer)
32     session.actions.perform([key_chain.dict, mouse_chain.dict])
33     expected = [
34         {"type": "mousemove"},
35         {"type": "mousedown"},
36         {"type": "mouseup"},
37         {"type": "click"},
38     ]
39     defaults = {
40         "altKey": False,
41         "metaKey": False,
42         "shiftKey": False,
43         "ctrlKey": False
44     }
45     for e in expected:
46         e.update(defaults)
47         if e["type"] != "mousemove":
48             e[prop] = True
49     filtered_events = [filter_dict(e, expected[0]) for e in get_events(session)]
50     assert expected == filtered_events
51
52
53 def test_release_control_click(session, key_reporter, key_chain, mouse_chain):
54     key_chain \
55         .pause(0) \
56         .key_down(Keys.CONTROL)
57     mouse_chain \
58         .pointer_move(0, 0, origin=key_reporter) \
59         .pointer_down()
60     session.actions.perform([key_chain.dict, mouse_chain.dict])
61     session.execute_script("""
62         var keyReporter = document.getElementById("keys");
63         ["mousedown", "mouseup"].forEach((e) => {
64             keyReporter.addEventListener(e, recordPointerEvent);
65           });
66         resetEvents();
67     """)
68     session.actions.release()
69     expected = [
70         {"type": "mouseup"},
71         {"type": "keyup"},
72     ]
73     events = [filter_dict(e, expected[0]) for e in get_events(session)]
74     assert events == expected