From 377c5eb43afea30f70c3eeccb84978813fc206bb Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Thu, 13 Apr 2023 16:18:24 +0000 Subject: [PATCH] Bug 1776190 - [marionette] Allow a modifier key to be reset when sending it again within the same command. r=webdriver-reviewers,jdescottes Differential Revision: https://phabricator.services.mozilla.com/D175242 --- remote/marionette/event.sys.mjs | 7 +++++- .../webdriver/element_send_keys/__init__.py | 0 .../webdriver/element_send_keys/send_keys.py | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 testing/web-platform/mozilla/tests/webdriver/element_send_keys/__init__.py create mode 100644 testing/web-platform/mozilla/tests/webdriver/element_send_keys/send_keys.py diff --git a/remote/marionette/event.sys.mjs b/remote/marionette/event.sys.mjs index 45570d3cb0b7..e01f1203dcab 100644 --- a/remote/marionette/event.sys.mjs +++ b/remote/marionette/event.sys.mjs @@ -262,7 +262,12 @@ event.sendKeys = function(keyString, win) { const data = lazy.keyData.getData(keyValue); const key = { ...data, ...modifiers }; if (data.modifier) { - modifiers[data.modifier] = true; + // Negating the state of the modifier here is not spec compliant but + // makes us compatible to Chrome's behavior for now. That's fine unless + // we know the correct behavior. + // + // @see: https://github.com/w3c/webdriver/issues/1734 + modifiers[data.modifier] = !modifiers[data.modifier]; } event.sendSingleKey(key, win); } diff --git a/testing/web-platform/mozilla/tests/webdriver/element_send_keys/__init__.py b/testing/web-platform/mozilla/tests/webdriver/element_send_keys/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/testing/web-platform/mozilla/tests/webdriver/element_send_keys/send_keys.py b/testing/web-platform/mozilla/tests/webdriver/element_send_keys/send_keys.py new file mode 100644 index 000000000000..1399959cebf9 --- /dev/null +++ b/testing/web-platform/mozilla/tests/webdriver/element_send_keys/send_keys.py @@ -0,0 +1,24 @@ +from tests.support.asserts import assert_success +from tests.support.keys import Keys + + +def element_send_keys(session, element, text): + return session.transport.send( + "POST", + "/session/{session_id}/element/{element_id}/value".format( + session_id=session.session_id, element_id=element.id + ), + {"text": text}, + ) + + +def test_modifier_key_toggles(session, inline, modifier_key): + session.url = inline("") + element = session.find.css("input", all=False) + + response = element_send_keys( + session, element, f"{modifier_key}a{modifier_key}{Keys.DELETE}cheese" + ) + assert_success(response) + + assert element.property("value") == "cheese"