Bug 1358020 - Prevent default behaviour when testing function keys; r=ato
authorMaja Frydrychowicz <mjzffr@gmail.com>
Fri, 26 May 2017 17:13:50 +0200
changeset 409114 261836433b949898383936ffbf1876834fa25649
parent 409113 8092c26b85d4273e0797638df567601e250808e0
child 409115 c4633ac3f49c3f3a8bdcc31df3720672f103939c
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1358020
milestone55.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 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)