-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Differential Revision: https://phabricator.services.mozilla.com/D157974 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1792090 gecko-commit: 90a1606bc5b8bf317ade1dee4dae849a583cdad3 gecko-reviewers: webdriver-reviewers, whimboo
- Loading branch information
Showing
6 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
|
||
from webdriver.bidi.modules.input import Actions | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_null_response_value(bidi_session, top_context): | ||
actions = Actions() | ||
actions.add_key().key_down("a").key_up("a") | ||
value = await bidi_session.input.perform_actions(actions=actions, | ||
context=top_context["context"]) | ||
assert value == {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
from webdriver.bidi.modules.input import Actions | ||
from webdriver.bidi.modules.script import ContextTarget | ||
|
||
from tests.support.helpers import filter_dict | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def get_events(context, bidi_session): | ||
"""Return list of key events recorded in the test_keys_page fixture.""" | ||
events_str = await bidi_session.script.evaluate(expression="JSON.stringify(allEvents.events)", | ||
target=ContextTarget(context), | ||
await_promise=False) | ||
events = json.loads(events_str["value"]) | ||
|
||
# `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in | ||
# test_actions.html), so this converts them back into unicode literals. | ||
for e in events: | ||
# example: turn "U+d83d" (6 chars) into u"\ud83d" (1 char) | ||
if "key" in e and e["key"].startswith(u"U+"): | ||
key = e["key"] | ||
hex_suffix = key[key.index("+") + 1:] | ||
e["key"] = chr(int(hex_suffix, 16)) | ||
|
||
# WebKit sets code as 'Unidentified' for unidentified key codes, but | ||
# tests expect ''. | ||
if "code" in e and e["code"] == "Unidentified": | ||
e["code"] = "" | ||
return events | ||
|
||
|
||
@pytest.mark.parametrize("value,code", [ | ||
(u"a", "KeyA",), | ||
("a", "KeyA",), | ||
(u"\"", "Quote"), | ||
(u",", "Comma"), | ||
(u"\u00E0", ""), | ||
(u"\u0416", ""), | ||
(u"@", "Digit2"), | ||
(u"\u2603", ""), | ||
(u"\uF6C2", ""), # PUA | ||
]) | ||
async def test_printable_key_sends_correct_events(bidi_session, top_context, url, value, code): | ||
await bidi_session.browsing_context.navigate( | ||
context=top_context["context"], | ||
url=url("/webdriver/tests/support/html/test_actions.html"), | ||
wait="complete" | ||
) | ||
await bidi_session.script.call_function(function_declaration=""" | ||
() => { | ||
let elem = document.getElementById("keys"); | ||
elem.focus(); | ||
resetEvents(); | ||
}""", | ||
target=ContextTarget(top_context["context"]), | ||
await_promise=False) | ||
|
||
actions = Actions() | ||
(actions.add_key() | ||
.key_down(value) | ||
.key_up(value)) | ||
await bidi_session.input.perform_actions(actions=actions, | ||
context=top_context["context"]) | ||
|
||
all_events = await get_events(top_context["context"], bidi_session) | ||
|
||
expected = [ | ||
{"code": code, "key": value, "type": "keydown"}, | ||
{"code": code, "key": value, "type": "keypress"}, | ||
{"code": code, "key": value, "type": "keyup"}, | ||
] | ||
|
||
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] | ||
events = [filter_dict(e, expected[0]) for e in events] | ||
assert events == expected | ||
|
||
keys_value = await bidi_session.script.call_function(function_declaration=""" | ||
() => { | ||
let elem = document.getElementById("keys"); | ||
return elem.value | ||
}""", | ||
target=ContextTarget(top_context["context"]), | ||
await_promise=False) | ||
|
||
assert keys_value["value"] == value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.