Bug 1405370 - [wdspec] Reorganize key action tests for "Perform Actions". r=ato
authorHenrik Skupin <mail@hskupin.info>
Thu, 20 Sep 2018 15:39:31 +0200
changeset 493503 7c1a9d25aaf013ee3ec9b6856445dabe5ac484a1
parent 493502 2998b10eb5a79d16557f5bf5b176482afe68522c
child 493504 bdb144bdca1649682b0a34712eb9aad3c4c799da
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1405370
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1405370 - [wdspec] Reorganize key action tests for "Perform Actions". r=ato
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/tests/perform_actions/key.py
testing/web-platform/tests/webdriver/tests/perform_actions/key_events.py
testing/web-platform/tests/webdriver/tests/perform_actions/key_special_keys.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -432128,28 +432128,34 @@
     ]
    ],
    "webdriver/tests/perform_actions/key.py": [
     [
      "/webdriver/tests/perform_actions/key.py",
      {}
     ]
    ],
+   "webdriver/tests/perform_actions/key_events.py": [
+    [
+     "/webdriver/tests/perform_actions/key_events.py",
+     {
+      "timeout": "long"
+     }
+    ]
+   ],
    "webdriver/tests/perform_actions/key_shortcuts.py": [
     [
      "/webdriver/tests/perform_actions/key_shortcuts.py",
      {}
     ]
    ],
    "webdriver/tests/perform_actions/key_special_keys.py": [
     [
      "/webdriver/tests/perform_actions/key_special_keys.py",
-     {
-      "timeout": "long"
-     }
+     {}
     ]
    ],
    "webdriver/tests/perform_actions/none.py": [
     [
      "/webdriver/tests/perform_actions/none.py",
      {}
     ]
    ],
@@ -662214,25 +662220,29 @@
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
    "support"
   ],
   "webdriver/tests/perform_actions/conftest.py": [
    "dffae0b98cd67c664883f4e4efd608415c82b179",
    "support"
   ],
   "webdriver/tests/perform_actions/key.py": [
-   "2e6cbdfbb32f9ada42c2b8a49f7702b14ffdc550",
+   "2b3414c5ebfd62955860de540b4614471efbe8ad",
+   "wdspec"
+  ],
+  "webdriver/tests/perform_actions/key_events.py": [
+   "462688a55e527ffd5d075e4bd981489e5e029f8c",
    "wdspec"
   ],
   "webdriver/tests/perform_actions/key_shortcuts.py": [
    "31b533ac8504108037ecccb76de2d089c1ad2a58",
    "wdspec"
   ],
   "webdriver/tests/perform_actions/key_special_keys.py": [
-   "4a55ccfa1d97b714a9145e148d73827b8b882642",
+   "003bba4294105eb2757bfbe9e4f808b4ea13047c",
    "wdspec"
   ],
   "webdriver/tests/perform_actions/none.py": [
    "07944a68ffeedfdbd5adac44244f6435b5c5c6cb",
    "wdspec"
   ],
   "webdriver/tests/perform_actions/pointer.py": [
    "9a68f322d70b585ad32e3814bb424fa5d817cc74",
--- a/testing/web-platform/tests/webdriver/tests/perform_actions/key.py
+++ b/testing/web-platform/tests/webdriver/tests/perform_actions/key.py
@@ -1,190 +1,25 @@
 import pytest
 
 from webdriver.error import NoSuchWindowException
 
 from tests.perform_actions.support.keys import Keys
-from tests.perform_actions.support.refine import filter_dict, get_events, get_keys
+from tests.perform_actions.support.refine import get_keys
 
 
 def test_null_response_value(session, key_chain):
     value = key_chain.key_up("a").perform()
     assert value is None
 
 
 def test_no_browsing_context(session, closed_window, key_chain):
     with pytest.raises(NoSuchWindowException):
         key_chain.key_up("a").perform()
 
 
-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
-
-
-@pytest.mark.parametrize("value,code", [
-    (u"a", "KeyA",),
-    ("a", "KeyA",),
-    (u"\"", "Quote"),
-    (u",", "Comma"),
-    (u"\u00E0", ""),
-    (u"\u0416", ""),
-    (u"@", "Digit2"),
-    (u"\u2603", ""),
-    (u"\uF6C2", ""),  # PUA
-])
-def test_single_printable_key_sends_correct_events(session,
-                                                   key_reporter,
-                                                   key_chain,
-                                                   value,
-                                                   code):
-    key_chain \
-        .key_down(value) \
-        .key_up(value) \
-        .perform()
-    expected = [
-        {"code": code, "key": value, "type": "keydown"},
-        {"code": code, "key": value, "type": "keypress"},
-        {"code": code, "key": value, "type": "keyup"},
-    ]
-    all_events = get_events(session)
-    events = [filter_dict(e, expected[0]) for e in all_events]
-    if len(events) > 0 and events[0]["code"] == None:
-        # Remove 'code' entry if browser doesn't support it
-        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
-        events = [filter_dict(e, expected[0]) for e in events]
-    assert events == expected
-    assert get_keys(key_reporter) == value
-
-
-@pytest.mark.parametrize("value", [
-    (u"\U0001F604"),
-    (u"\U0001F60D"),
-])
-def test_single_emoji_records_correct_key(session, key_reporter, key_chain, value):
-    # Not using key_chain.send_keys() because we always want to treat value as
-    # one character here. `len(value)` varies by platform for non-BMP characters,
-    # so we don't want to iterate over value.
-    key_chain \
-        .key_down(value) \
-        .key_up(value) \
-        .perform()
-    # events sent by major browsers are inconsistent so only check key value
-    assert get_keys(key_reporter) == value
-
-
-@pytest.mark.parametrize("value,code,key", [
-    (u"\uE050", "ShiftRight", "Shift"),
-    (u"\uE053", "OSRight", "Meta"),
-    (Keys.CONTROL, "ControlLeft", "Control"),
-])
-def test_single_modifier_key_sends_correct_events(session,
-                                                  key_reporter,
-                                                  key_chain,
-                                                  value,
-                                                  code,
-                                                  key):
-    key_chain \
-        .key_down(value) \
-        .key_up(value) \
-        .perform()
-    all_events = get_events(session)
-    expected = [
-        {"code": code, "key": key, "type": "keydown"},
-        {"code": code, "key": key, "type": "keyup"},
-    ]
-    events = [filter_dict(e, expected[0]) for e in all_events]
-    if len(events) > 0 and events[0]["code"] == None:
-        # Remove 'code' entry if browser doesn't support it
-        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
-        events = [filter_dict(e, expected[0]) for e in events]
-    assert events == expected
-    assert len(get_keys(key_reporter)) == 0
-
-
-@pytest.mark.parametrize("value,code,key", [
-    (Keys.ESCAPE, "Escape", "Escape"),
-    (Keys.RIGHT, "ArrowRight", "ArrowRight"),
-])
-def test_single_nonprintable_key_sends_events(session,
-                                              key_reporter,
-                                              key_chain,
-                                              value,
-                                              code,
-                                              key):
-    key_chain \
-        .key_down(value) \
-        .key_up(value) \
-        .perform()
-    expected = [
-        {"code": code, "key": key, "type": "keydown"},
-        {"code": code, "key": key, "type": "keypress"},
-        {"code": code, "key": key, "type": "keyup"},
-    ]
-    all_events = get_events(session)
-    events = [filter_dict(e, expected[0]) for e in all_events]
-    if len(events) > 0 and events[0]["code"] == None:
-        # Remove 'code' entry if browser doesn't support it
-        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
-        events = [filter_dict(e, expected[0]) for e in events]
-    if len(events) == 2:
-        # most browsers don't send a keypress for non-printable keys
-        assert events == [expected[0], expected[2]]
-    else:
-        assert events == expected
-    assert len(get_keys(key_reporter)) == 0
-
-
-def test_sequence_of_keydown_printable_keys_sends_events(session,
-                                                         key_reporter,
-                                                         key_chain):
-    key_chain \
-        .key_down("a") \
-        .key_down("b") \
-        .perform()
-    expected = [
-        {"code": "KeyA", "key": "a", "type": "keydown"},
-        {"code": "KeyA", "key": "a", "type": "keypress"},
-        {"code": "KeyB", "key": "b", "type": "keydown"},
-        {"code": "KeyB", "key": "b", "type": "keypress"},
-    ]
-    all_events = get_events(session)
-    events = [filter_dict(e, expected[0]) for e in all_events]
-    if len(events) > 0 and events[0]["code"] == None:
-        # Remove 'code' entry if browser doesn't support it
-        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
-        events = [filter_dict(e, expected[0]) for e in events]
-    assert events == expected
-    assert get_keys(key_reporter) == "ab"
-
-
-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"},
-    ]
-    all_events = get_events(session)
-    events = [filter_dict(e, expected[0]) for e in all_events]
-    if len(events) > 0 and events[0]["code"] == None:
-        # Remove 'code' entry if browser doesn't support it
-        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
-        events = [filter_dict(e, expected[0]) for e in events]
-    assert events == expected
-    assert get_keys(key_reporter) == "ef"
-
-
 def test_backspace_erases_keys(session, key_reporter, key_chain):
     key_chain \
         .send_keys("efcd") \
         .send_keys([Keys.BACKSPACE, Keys.BACKSPACE]) \
         .perform()
+
     assert get_keys(key_reporter) == "ef"
-
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/perform_actions/key_events.py
@@ -0,0 +1,205 @@
+# META: timeout=long
+
+import pytest
+
+from tests.perform_actions.support.keys import ALL_EVENTS, Keys
+from tests.perform_actions.support.refine import filter_dict, get_events, get_keys
+
+
+def test_keyup_only_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
+
+
+@pytest.mark.parametrize("key, event", [
+    (Keys.ALT, "ALT"),
+    (Keys.CONTROL, "CONTROL"),
+    (Keys.META, "META"),
+    (Keys.SHIFT, "SHIFT"),
+    (Keys.R_ALT, "R_ALT"),
+    (Keys.R_CONTROL, "R_CONTROL"),
+    (Keys.R_META, "R_META"),
+    (Keys.R_SHIFT, "R_SHIFT"),
+])
+def test_modifier_key_sends_correct_events(session, key_reporter, key_chain, key, event):
+    code = ALL_EVENTS[event]["code"]
+    value = ALL_EVENTS[event]["key"]
+
+    key_chain \
+        .key_down(key) \
+        .key_up(key) \
+        .perform()
+    all_events = get_events(session)
+
+    expected = [
+        {"code": code, "key": value, "type": "keydown"},
+        {"code": code, "key": value, "type": "keyup"},
+    ]
+
+    events = [filter_dict(e, expected[0]) for e in all_events]
+    if len(events) > 0 and events[0]["code"] is None:
+        # Remove 'code' entry if browser doesn't support it
+        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
+        events = [filter_dict(e, expected[0]) for e in events]
+    assert events == expected
+
+    assert len(get_keys(key_reporter)) == 0
+
+
+@pytest.mark.parametrize("key,event", [
+    (Keys.ESCAPE, "ESCAPE"),
+    (Keys.RIGHT, "RIGHT"),
+])
+def test_non_printable_key_sends_events(session, key_reporter, key_chain, key, event):
+    code = ALL_EVENTS[event]["code"]
+    value = ALL_EVENTS[event]["key"]
+
+    key_chain \
+        .key_down(key) \
+        .key_up(key) \
+        .perform()
+    all_events = get_events(session)
+
+    expected = [
+        {"code": code, "key": value, "type": "keydown"},
+        {"code": code, "key": value, "type": "keypress"},
+        {"code": code, "key": value, "type": "keyup"},
+    ]
+
+    events = [filter_dict(e, expected[0]) for e in all_events]
+    if len(events) > 0 and events[0]["code"] is None:
+        # Remove 'code' entry if browser doesn't support it
+        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
+        events = [filter_dict(e, expected[0]) for e in events]
+    if len(events) == 2:
+        # most browsers don't send a keypress for non-printable keys
+        assert events == [expected[0], expected[2]]
+    else:
+        assert events == expected
+
+    assert len(get_keys(key_reporter)) == 0
+
+
+@pytest.mark.parametrize("value,code", [
+    (u"a", "KeyA",),
+    ("a", "KeyA",),
+    (u"\"", "Quote"),
+    (u",", "Comma"),
+    (u"\u00E0", ""),
+    (u"\u0416", ""),
+    (u"@", "Digit2"),
+    (u"\u2603", ""),
+    (u"\uF6C2", ""),  # PUA
+])
+def test_printable_key_sends_correct_events(session, key_reporter, key_chain, value, code):
+    key_chain \
+        .key_down(value) \
+        .key_up(value) \
+        .perform()
+    all_events = get_events(session)
+
+    expected = [
+        {"code": code, "key": value, "type": "keydown"},
+        {"code": code, "key": value, "type": "keypress"},
+        {"code": code, "key": value, "type": "keyup"},
+    ]
+
+    events = [filter_dict(e, expected[0]) for e in all_events]
+    if len(events) > 0 and events[0]["code"] is None:
+        # Remove 'code' entry if browser doesn't support it
+        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
+        events = [filter_dict(e, expected[0]) for e in events]
+    assert events == expected
+
+    assert get_keys(key_reporter) == value
+
+
+def test_sequence_of_keydown_printable_keys_sends_events(session, key_reporter, key_chain):
+    key_chain \
+        .key_down("a") \
+        .key_down("b") \
+        .perform()
+    all_events = get_events(session)
+
+    expected = [
+        {"code": "KeyA", "key": "a", "type": "keydown"},
+        {"code": "KeyA", "key": "a", "type": "keypress"},
+        {"code": "KeyB", "key": "b", "type": "keydown"},
+        {"code": "KeyB", "key": "b", "type": "keypress"},
+    ]
+
+    events = [filter_dict(e, expected[0]) for e in all_events]
+    if len(events) > 0 and events[0]["code"] is None:
+        # Remove 'code' entry if browser doesn't support it
+        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
+        events = [filter_dict(e, expected[0]) for e in events]
+    assert events == expected
+
+    assert get_keys(key_reporter) == "ab"
+
+
+def test_sequence_of_keydown_printable_characters_sends_events(session, key_reporter, key_chain):
+    key_chain.send_keys("ef").perform()
+    all_events = get_events(session)
+
+    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 all_events]
+    if len(events) > 0 and events[0]["code"] is None:
+        # Remove 'code' entry if browser doesn't support it
+        expected = [filter_dict(e, {"key": "", "type": ""}) for e in expected]
+        events = [filter_dict(e, expected[0]) for e in events]
+    assert events == expected
+
+    assert get_keys(key_reporter) == "ef"
+
+
+@pytest.mark.parametrize("name,expected", ALL_EVENTS.items())
+def test_special_key_sends_keydown(session, key_reporter, key_chain, name, expected):
+    if name.startswith("F"):
+        # Prevent default behavior for F1, etc., but only after keydown
+        # bubbles up to body. (Otherwise activated browser menus/functions
+        # may interfere with subsequent tests.)
+        session.execute_script("""
+            document.body.addEventListener("keydown",
+                    function(e) { e.preventDefault() });
+        """)
+    if (session.capabilities["browserName"] == 'internet explorer'):
+        key_reporter.click()
+        session.execute_script("resetEvents();")
+    key_chain.key_down(getattr(Keys, name)).perform()
+
+    # only interested in keydown
+    first_event = get_events(session)[0]
+    # make a copy so we can throw out irrelevant keys and compare to events
+    expected = dict(expected)
+
+    del expected["value"]
+
+    # check and remove keys that aren't in expected
+    assert first_event["type"] == "keydown"
+    assert first_event["repeat"] is False
+    first_event = filter_dict(first_event, expected)
+    if first_event["code"] is None:
+        del first_event["code"]
+        del expected["code"]
+    assert first_event == expected
+    # only printable characters should be recorded in input field
+    entered_keys = get_keys(key_reporter)
+    if len(expected["key"]) == 1:
+        assert entered_keys == expected["key"]
+    else:
+        assert len(entered_keys) == 0
--- a/testing/web-platform/tests/webdriver/tests/perform_actions/key_special_keys.py
+++ b/testing/web-platform/tests/webdriver/tests/perform_actions/key_special_keys.py
@@ -1,84 +1,38 @@
-# META: timeout=long
-
 import pytest
 
 from webdriver import error
 
-from tests.perform_actions.support.keys import ALL_EVENTS, Keys
-from tests.perform_actions.support.refine import filter_dict, get_events, get_keys
-
-
-@pytest.mark.parametrize("name,expected", ALL_EVENTS.items())
-def test_webdriver_special_key_sends_keydown(session,
-                                             key_reporter,
-                                             key_chain,
-                                             name,
-                                             expected):
-    if name.startswith("F"):
-        # Prevent default behavior for F1, etc., but only after keydown
-        # bubbles up to body. (Otherwise activated browser menus/functions
-        # may interfere with subsequent tests.)
-        session.execute_script("""
-            document.body.addEventListener("keydown",
-                    function(e) { e.preventDefault() });
-        """)
-    if (session.capabilities["browserName"] == 'internet explorer'):
-        key_reporter.click()
-        session.execute_script("resetEvents();")
-    key_chain.key_down(getattr(Keys, name)).perform()
-
-    # only interested in keydown
-    first_event = get_events(session)[0]
-    # make a copy so we can throw out irrelevant keys and compare to events
-    expected = dict(expected)
-
-    del expected["value"]
-
-    # check and remove keys that aren't in expected
-    assert first_event["type"] == "keydown"
-    assert first_event["repeat"] == False
-    first_event = filter_dict(first_event, expected)
-    if first_event["code"] == None:
-        del first_event["code"]
-        del expected["code"]
-    assert first_event == expected
-    # only printable characters should be recorded in input field
-    entered_keys = get_keys(key_reporter)
-    if len(expected["key"]) == 1:
-        assert entered_keys == expected["key"]
-    else:
-        assert len(entered_keys) == 0
+from tests.perform_actions.support.refine import get_keys
 
 
 @pytest.mark.parametrize("value", [
-    (u"f"),
+    (u"\U0001F604"),
+    (u"\U0001F60D"),
     (u"\u0BA8\u0BBF"),
     (u"\u1100\u1161\u11A8"),
 ])
-def test_multiple_codepoint_keys_behave_correctly(session,
-                                                  key_reporter,
-                                                  key_chain,
-                                                  value):
+def test_codepoint_keys_behave_correctly(session, key_reporter, key_chain, value):
+    # Not using key_chain.send_keys() because we always want to treat value as
+    # one character here. `len(value)` varies by platform for non-BMP characters,
+    # so we don't want to iterate over value.
     key_chain \
         .key_down(value) \
         .key_up(value) \
         .perform()
 
+    # events sent by major browsers are inconsistent so only check key value
     assert get_keys(key_reporter) == value
 
 
 @pytest.mark.parametrize("value", [
     (u"fa"),
     (u"\u0BA8\u0BBFb"),
     (u"\u0BA8\u0BBF\u0BA8"),
     (u"\u1100\u1161\u11A8c")
 ])
-def test_invalid_multiple_codepoint_keys_fail(session,
-                                              key_reporter,
-                                              key_chain,
-                                              value):
+def test_invalid_multiple_codepoint_keys_fail(session, key_reporter, key_chain, value):
     with pytest.raises(error.InvalidArgumentException):
         key_chain \
             .key_down(value) \
             .key_up(value) \
-            .perform()
\ No newline at end of file
+            .perform()