a1d454d1fe2338c59e873b4582c7a9129e65ec72
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / element_send_keys / scroll_into_view.py
1 from tests.support.asserts import assert_success
2 from tests.support.fixtures import is_element_in_viewport
3 from tests.support.inline import inline
4
5
6 def send_keys_to_element(session, element, text):
7     return session.transport.send(
8         "POST",
9         "/session/{session_id}/element/{element_id}/value".format(
10             session_id=session.session_id,
11             element_id=element.id),
12         {"text": text})
13
14
15 def test_element_outside_of_not_scrollable_viewport(session):
16     session.url = inline("<input style=\"position: relative; left: -9999px;\">")
17     element = session.find.css("input", all=False)
18
19     response = send_keys_to_element(session, element, "foo")
20     assert_success(response)
21
22     assert not is_element_in_viewport(session, element)
23
24
25 def test_element_outside_of_scrollable_viewport(session):
26     session.url = inline("<input style=\"margin-top: 102vh;\">")
27     element = session.find.css("input", all=False)
28
29     response = send_keys_to_element(session, element, "foo")
30     assert_success(response)
31
32     assert is_element_in_viewport(session, element)
33
34
35 def test_option_select_container_outside_of_scrollable_viewport(session):
36     session.url = inline("""
37         <select style="margin-top: 102vh;">
38           <option value="foo">foo</option>
39           <option value="bar" id="bar">bar</option>
40         </select>
41     """)
42     element = session.find.css("option#bar", all=False)
43     select = session.find.css("select", all=False)
44
45     response = send_keys_to_element(session, element, "bar")
46     assert_success(response)
47
48     assert is_element_in_viewport(session, select)
49     assert is_element_in_viewport(session, element)
50
51
52 def test_option_stays_outside_of_scrollable_viewport(session):
53     session.url = inline("""
54         <select multiple style="height: 105vh; margin-top: 100vh;">
55           <option value="foo" id="foo" style="height: 100vh;">foo</option>
56           <option value="bar" id="bar" style="background-color: yellow;">bar</option>
57         </select>
58     """)
59     select = session.find.css("select", all=False)
60     option_foo = session.find.css("option#foo", all=False)
61     option_bar = session.find.css("option#bar", all=False)
62
63     response = send_keys_to_element(session, option_bar, "bar")
64     assert_success(response)
65
66     assert is_element_in_viewport(session, select)
67     assert is_element_in_viewport(session, option_foo)
68     assert not is_element_in_viewport(session, option_bar)
69
70
71 def test_contenteditable_element_outside_of_scrollable_viewport(session):
72     session.url = inline("<div contenteditable style=\"margin-top: 102vh;\"></div>")
73     element = session.find.css("div", all=False)
74
75     response = send_keys_to_element(session, element, "foo")
76     assert_success(response)
77
78     assert is_element_in_viewport(session, element)