From 6760851fd6f353e44921471c11cf30f2794aec66 Mon Sep 17 00:00:00 2001 From: jimevans Date: Tue, 12 Feb 2019 14:40:39 +0000 Subject: [PATCH] Bug 1526555 [wpt PR 15204] - Enabling older browsers values for KeyboardEvent.key in WebDriver tests, a=testonly Automatic update from web-platform-tests webdriver: enable older browsers values for KeyboardEvent.key (#15204) When propagating keyboard events, older browsers use different strings for the "key" property of the KeyboardEvent object. This commit enables the ability of the WebDriver tests for keyboard events to validate the comparison to these older values in addition to the values used by modern browsers. See the footnotes in the sections of the following: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values -- wpt-commits: b879d5c7d8103cdb6948c2a4d8d8b31f845dae7b wpt-pr: 15204 --- .../tests/perform_actions/key_events.py | 23 +++++++++++++++---- .../tests/perform_actions/pointer.py | 2 ++ .../tests/perform_actions/support/keys.py | 21 +++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/testing/web-platform/tests/webdriver/tests/perform_actions/key_events.py b/testing/web-platform/tests/webdriver/tests/perform_actions/key_events.py index a5ab34ba0068..c00e3296367c 100644 --- a/testing/web-platform/tests/webdriver/tests/perform_actions/key_events.py +++ b/testing/web-platform/tests/webdriver/tests/perform_actions/key_events.py @@ -1,8 +1,9 @@ # META: timeout=long import pytest +import copy -from tests.perform_actions.support.keys import ALL_EVENTS, Keys +from tests.perform_actions.support.keys import ALL_EVENTS, Keys, ALTERNATIVE_KEY_NAMES from tests.perform_actions.support.refine import filter_dict, get_events, get_keys @@ -75,16 +76,24 @@ def test_non_printable_key_sends_events(session, key_reporter, key_chain, key, e {"code": code, "key": value, "type": "keyup"}, ] + # Make a copy for alternate key property values + # Note: only keydown and keyup are affected by alternate key names + alt_expected = copy.deepcopy(expected) + if event in ALTERNATIVE_KEY_NAMES: + alt_expected[0]["key"] = ALTERNATIVE_KEY_NAMES[event] + alt_expected[2]["key"] = ALTERNATIVE_KEY_NAMES[event] + 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] + alt_expected = [filter_dict(e, {"key": "", "type": ""}) for e in alt_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]] + assert events == [expected[0], expected[2]] or events == [alt_expected[0], alt_expected[2]] else: - assert events == expected + assert events == expected or events == alt_expected assert len(get_keys(key_reporter)) == 0 @@ -192,6 +201,11 @@ def test_special_key_sends_keydown(session, key_reporter, key_chain, name, expec del expected["value"] + # make another copy for alternative key names + alt_expected = copy.deepcopy(expected) + if name in ALTERNATIVE_KEY_NAMES: + alt_expected["key"] = ALTERNATIVE_KEY_NAMES[name] + # check and remove keys that aren't in expected assert first_event["type"] == "keydown" assert first_event["repeat"] is False @@ -199,7 +213,8 @@ def test_special_key_sends_keydown(session, key_reporter, key_chain, name, expec if first_event["code"] is None: del first_event["code"] del expected["code"] - assert first_event == expected + del alt_expected["code"] + assert first_event == expected or first_event == alt_expected # only printable characters should be recorded in input field entered_keys = get_keys(key_reporter) if len(expected["key"]) == 1: diff --git a/testing/web-platform/tests/webdriver/tests/perform_actions/pointer.py b/testing/web-platform/tests/webdriver/tests/perform_actions/pointer.py index cb270126438a..6719272c3f1e 100644 --- a/testing/web-platform/tests/webdriver/tests/perform_actions/pointer.py +++ b/testing/web-platform/tests/webdriver/tests/perform_actions/pointer.py @@ -1,3 +1,5 @@ +# META: timeout=long + import pytest from webdriver.error import NoSuchWindowException diff --git a/testing/web-platform/tests/webdriver/tests/perform_actions/support/keys.py b/testing/web-platform/tests/webdriver/tests/perform_actions/support/keys.py index 68e37b34e030..d30ee91b5a61 100644 --- a/testing/web-platform/tests/webdriver/tests/perform_actions/support/keys.py +++ b/testing/web-platform/tests/webdriver/tests/perform_actions/support/keys.py @@ -740,6 +740,27 @@ ALL_EVENTS = { } } +ALTERNATIVE_KEY_NAMES = { + "ADD": "Add", + "DECIMAL": "Decimal", + "DELETE": "Del", + "DIVIDE": "Divide", + "DOWN": "Down", + "ESCAPE": "Esc", + "LEFT": "Left", + "MULTIPLY": "Multiply", + "R_ARROWDOWN": "Down", + "R_ARROWLEFT": "Left", + "R_ARROWRIGHT": "Right", + "R_ARROWUP": "Up", + "R_DELETE": "Del", + "RIGHT": "Right", + "SEPARATOR": "Separator", + "SPACE": "Spacebar", + "SUBTRACT": "Subtract", + "UP": "Up", +} + if sys.platform == "darwin": MODIFIER_KEY = Keys.META else: