From 09f4f49fda7f191ccd52bac2dc6be5cab44bd9f0 Mon Sep 17 00:00:00 2001 From: Simon Kobyda Date: Thu, 5 Oct 2023 10:18:12 +0200 Subject: [PATCH] test: Follow ASCII chart instead of browser's keycodes Until now, we were mapping values of characters to their browser's keycodes values [1]. This however is incorrect, since to get a value of character, we use Python's 'ord' function, which returns character's Unicode value. In some cases, these values are different. For example, a value for Enter has keycode '13' in browser [1], but Python's 'ord' will give us value of '10' for a line feed character. [2] [1] https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode [2] https://python-reference.readthedocs.io/en/latest/docs/str/ASCII.html --- test/common/testlib.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/common/testlib.py b/test/common/testlib.py index 5794571cbed9..a3efba4c75a8 100644 --- a/test/common/testlib.py +++ b/test/common/testlib.py @@ -490,11 +490,13 @@ def _key_press_chromium(self, keys: str, modifiers: int = 0, use_ord=False): self.cdp.invoke("Input.dispatchKeyEvent", **args) def _key_press_firefox(self, keys: str, modifiers: int = 0, use_ord: bool = False): - # https://github.com/GoogleChrome/puppeteer/blob/master/lib/USKeyboardLayout.js + # https://python-reference.readthedocs.io/en/latest/docs/str/ASCII.html + # Both line feed and carriage return are normalized to Enter (https://html.spec.whatwg.org/multipage/form-elements.html) keyMap = { 8: "Backspace", # Backspace key 9: "Tab", # Tab key - 13: "Enter", # Enter key + 10: "Enter", # Enter key (normalized from line feed) + 13: "Enter", # Enter key (normalized from carriage return) 27: "Escape", # Escape key 37: "ArrowLeft", # Arrow key left 40: "ArrowDown", # Arrow key down