Bug 1358020 - Prevent default behaviour when testing function keys; r?ato draft
authorMaja Frydrychowicz <mjzffr@gmail.com>
Fri, 26 May 2017 17:13:50 +0200
changeset 585124 79e4e333b5a5b692f4015c68435b957c8a66b35e
parent 585005 44e41de60c48a94a004494dd48f57dd1d8c157d8
child 630637 701a1071ea685152116d1c260ff091dd02eff061
push id61016
push userbmo:mjzffr@gmail.com
push dateFri, 26 May 2017 15:34:46 +0000
reviewersato
bugs1358020
milestone55.0a1
Bug 1358020 - Prevent default behaviour when testing function keys; r?ato F10, F7 and others activate browser menus in the Linux test environment, so call preventDefault to stop it. The default bevahiour interferes with tests running against the upcoming beta build. Although nightly builds also have this behaviour, it doesn't appear to intefere with the tests. MozReview-Commit-ID: 1PiqmtG1SfB
testing/web-platform/tests/webdriver/actions/special_keys.py
--- a/testing/web-platform/tests/webdriver/actions/special_keys.py
+++ b/testing/web-platform/tests/webdriver/actions/special_keys.py
@@ -6,23 +6,30 @@ from support.refine import filter_dict, 
 
 
 @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",
+                    (e) => e.preventDefault());
+        """)
     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)
     assert first_event == expected
     # only printable characters should be recorded in input field
     entered_keys = get_keys(key_reporter)