Bug 1337133 - Split test kinds, common fixtures, utilities in wdspec tests; r=ato+446296
authorMaja Frydrychowicz <mjzffr@gmail.com>
Mon, 27 Feb 2017 09:52:23 -0500
changeset 490196 be1184fd991140be31772d89f90c36ec84f958f4
parent 490195 2d7d58a97e464eb012500cf78fba8eb140361bcc
child 490197 1e827bb8b11ad6d0e004543b3f5d959a7b14def1
push id47030
push userbmo:ttromey@mozilla.com
push dateMon, 27 Feb 2017 20:32:32 +0000
reviewersato
bugs1337133, 446296
milestone54.0a1
Bug 1337133 - Split test kinds, common fixtures, utilities in wdspec tests; r=ato+446296 MozReview-Commit-ID: H2vSkhlfwE9
testing/web-platform/meta/webdriver/actions.py.ini
testing/web-platform/meta/webdriver/actions/key.py.ini
testing/web-platform/meta/webdriver/actions/sequence.py.ini
testing/web-platform/tests/test_keys_wdspec.html
testing/web-platform/tests/webdriver/actions.py
testing/web-platform/tests/webdriver/actions/__init__.py
testing/web-platform/tests/webdriver/actions/conftest.py
testing/web-platform/tests/webdriver/actions/key.py
testing/web-platform/tests/webdriver/actions/mouse.py
testing/web-platform/tests/webdriver/actions/sequence.py
testing/web-platform/tests/webdriver/actions/support/__init__.py
testing/web-platform/tests/webdriver/actions/support/keys.py
testing/web-platform/tests/webdriver/actions/support/refine.py
testing/web-platform/tests/webdriver/actions/support/test_actions_wdspec.html
testing/web-platform/tests/webdriver/support/__init__.py
testing/web-platform/tests/webdriver/support/keys.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/webdriver/actions/key.py.ini
@@ -0,0 +1,5 @@
+[key.py]
+  type: wdspec
+  disabled:
+    if (os == "linux") and (bits == 64) and debug: https://bugzilla.mozilla.org/show_bug.cgi?id=1318724
+  expected: CRASH
rename from testing/web-platform/meta/webdriver/actions.py.ini
rename to testing/web-platform/meta/webdriver/actions/sequence.py.ini
--- a/testing/web-platform/meta/webdriver/actions.py.ini
+++ b/testing/web-platform/meta/webdriver/actions/sequence.py.ini
@@ -1,5 +1,5 @@
-[actions.py]
+[sequence.py]
   type: wdspec
   disabled:
     if (os == "linux") and (bits == 64) and debug: https://bugzilla.mozilla.org/show_bug.cgi?id=1318724
   expected: CRASH
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/actions/conftest.py
@@ -0,0 +1,26 @@
+import pytest
+
+
+@pytest.fixture
+def key_chain(session):
+    return session.actions.sequence("key", "keyboard_id")
+
+
+@pytest.fixture(autouse=True)
+def release_actions(session, request):
+    # release all actions after each test
+    # equivalent to a teardown_function, but with access to session fixture
+    request.addfinalizer(session.actions.release)
+
+
+@pytest.fixture
+def key_reporter(session, test_actions_page, request):
+    """Represents focused input element from `test_keys_page` fixture."""
+    input_el = session.find.css("#keys", all=False)
+    input_el.click()
+    return input_el
+
+
+@pytest.fixture
+def test_actions_page(session, server):
+    session.url = server.where_is("webdriver/actions/support/test_actions_wdspec.html")
rename from testing/web-platform/tests/webdriver/actions.py
rename to testing/web-platform/tests/webdriver/actions/key.py
--- a/testing/web-platform/tests/webdriver/actions.py
+++ b/testing/web-platform/tests/webdriver/actions/key.py
@@ -1,79 +1,28 @@
 import pytest
 
 from support.keys import Keys
+from support.refine import get_keys, filter_dict
 
 
 def get_events(session):
     """Return list of key events recorded in the test_keys_page fixture."""
     events = session.execute_script("return allEvents.events;") or []
     # `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in
     # test_keys_wdspec.html), so this converts them back into unicode literals.
     for e in events:
         # example: turn "U+d83d" (6 chars) into u"\ud83d" (1 char)
         if e["key"].startswith(u"U+"):
             key = e["key"]
             hex_suffix = key[key.index("+") + 1:]
             e["key"] = unichr(int(hex_suffix, 16))
     return events
 
 
-def get_keys(input_el):
-    """Get printable characters entered into `input_el`.
-
-    :param input_el: HTML input element.
-    """
-    rv = input_el.property("value")
-    if rv is None:
-        return ""
-    else:
-        return rv
-
-
-def filter_dict(source, d):
-    """Filter `source` dict to only contain same keys as `d` dict.
-
-    :param source: dictionary to filter.
-    :param d: dictionary whose keys determine the filtering.
-    """
-    return {k: source[k] for k in d.keys()}
-
-
-@pytest.fixture
-def key_reporter(session, test_keys_page, request):
-    """Represents focused input element from `test_keys_page` fixture."""
-    input_el = session.find.css("#keys", all=False)
-    input_el.click()
-    return input_el
-
-
-@pytest.fixture
-def test_keys_page(session, server):
-    session.url = server.where_is("test_keys_wdspec.html")
-
-
-@pytest.fixture
-def key_chain(session):
-    return session.actions.sequence("key", "keyboard_id")
-
-
-@pytest.fixture(autouse=True)
-def release_actions(session, request):
-    # release all actions after each test
-    # equivalent to a teardown_function, but with access to session fixture
-    request.addfinalizer(session.actions.release)
-
-
-def test_no_actions_send_no_events(session, key_reporter, key_chain):
-    key_chain.perform()
-    assert len(get_keys(key_reporter)) == 0
-    assert len(get_events(session)) == 0
-
-
 def test_lone_keyup_sends_no_events(session, key_reporter, key_chain):
     key_chain.key_up("a").perform()
     assert len(get_keys(key_reporter)) == 0
     assert len(get_events(session)) == 0
     session.actions.release()
     assert len(get_keys(key_reporter)) == 0
     assert len(get_events(session)) == 0
 
@@ -215,45 +164,21 @@ def test_sequence_of_keydown_printable_k
         {"code": "KeyB", "key": "b", "type": "keydown"},
         {"code": "KeyB", "key": "b", "type": "keypress"},
     ]
     events = [filter_dict(e, expected[0]) for e in get_events(session)]
     assert events == expected
     assert get_keys(key_reporter) == "ab"
 
 
-def test_release_char_sequence_sends_keyup_events_in_reverse(session,
-                                                             key_reporter,
-                                                             key_chain):
-    key_chain \
-        .key_down("a") \
-        .key_down("b") \
-        .perform()
-    # reset so we only see the release events
-    session.execute_script("resetEvents();")
-    session.actions.release()
-    expected = [
-        {"code": "KeyB", "key": "b", "type": "keyup"},
-        {"code": "KeyA", "key": "a", "type": "keyup"},
-    ]
-    events = [filter_dict(e, expected[0]) for e in get_events(session)]
-    assert events == expected
-
-
 def test_sequence_of_keydown_character_keys(session, key_reporter, key_chain):
     key_chain.send_keys("ef").perform()
     expected = [
         {"code": "KeyE", "key": "e", "type": "keydown"},
         {"code": "KeyE", "key": "e", "type": "keypress"},
         {"code": "KeyE", "key": "e", "type": "keyup"},
         {"code": "KeyF", "key": "f", "type": "keydown"},
         {"code": "KeyF", "key": "f", "type": "keypress"},
         {"code": "KeyF", "key": "f", "type": "keyup"},
     ]
     events = [filter_dict(e, expected[0]) for e in get_events(session)]
     assert events == expected
     assert get_keys(key_reporter) == "ef"
-
-
-def test_release_no_actions_sends_no_events(session, key_reporter, key_chain):
-    session.actions.release()
-    assert len(get_keys(key_reporter)) == 0
-    assert len(get_events(session)) == 0
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/actions/mouse.py
@@ -0,0 +1,4 @@
+import pytest
+
+def test_nothing():
+    assert True
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/actions/sequence.py
@@ -0,0 +1,45 @@
+from support.refine import get_keys, filter_dict
+
+
+def get_events(session):
+    """Return list of key events recorded in the test_keys_page fixture."""
+    events = session.execute_script("return allEvents.events;") or []
+    # `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in
+    # test_keys_wdspec.html), so this converts them back into unicode literals.
+    for e in events:
+        # example: turn "U+d83d" (6 chars) into u"\ud83d" (1 char)
+        if e["key"].startswith(u"U+"):
+            key = e["key"]
+            hex_suffix = key[key.index("+") + 1:]
+            e["key"] = unichr(int(hex_suffix, 16))
+    return events
+
+
+def test_no_actions_send_no_events(session, key_reporter, key_chain):
+    key_chain.perform()
+    assert len(get_keys(key_reporter)) == 0
+    assert len(get_events(session)) == 0
+
+
+def test_release_char_sequence_sends_keyup_events_in_reverse(session,
+                                                             key_reporter,
+                                                             key_chain):
+    key_chain \
+        .key_down("a") \
+        .key_down("b") \
+        .perform()
+    # reset so we only see the release events
+    session.execute_script("resetEvents();")
+    session.actions.release()
+    expected = [
+        {"code": "KeyB", "key": "b", "type": "keyup"},
+        {"code": "KeyA", "key": "a", "type": "keyup"},
+    ]
+    events = [filter_dict(e, expected[0]) for e in get_events(session)]
+    assert events == expected
+
+
+def test_release_no_actions_sends_no_events(session, key_reporter):
+    session.actions.release()
+    assert len(get_keys(key_reporter)) == 0
+    assert len(get_events(session)) == 0
rename from testing/web-platform/tests/webdriver/support/__init__.py
rename to testing/web-platform/tests/webdriver/actions/support/__init__.py
rename from testing/web-platform/tests/webdriver/support/keys.py
rename to testing/web-platform/tests/webdriver/actions/support/keys.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/actions/support/refine.py
@@ -0,0 +1,19 @@
+def get_keys(input_el):
+    """Get printable characters entered into `input_el`.
+
+    :param input_el: HTML input element.
+    """
+    rv = input_el.property("value")
+    if rv is None:
+        return ""
+    else:
+        return rv
+
+
+def filter_dict(source, d):
+    """Filter `source` dict to only contain same keys as `d` dict.
+
+    :param source: dictionary to filter.
+    :param d: dictionary whose keys determine the filtering.
+    """
+    return {k: source[k] for k in d.keys()}
rename from testing/web-platform/tests/test_keys_wdspec.html
rename to testing/web-platform/tests/webdriver/actions/support/test_actions_wdspec.html
--- a/testing/web-platform/tests/test_keys_wdspec.html
+++ b/testing/web-platform/tests/webdriver/actions/support/test_actions_wdspec.html
@@ -1,12 +1,13 @@
+
 <!doctype html>
 <meta charset=utf-8>
 <head>
-    <title>Test Keys</title>
+    <title>Test Actions</title>
     <script>
         var allEvents = {events: []};
         function displayMessage(message) {
             document.getElementById("events").innerHTML = "<p>" + message + "</p>";
         }
 
         function appendMessage(message) {
             document.getElementById("events").innerHTML += "<p>" + message + "</p>";