зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1337133 - Set up fixtures for mouse actions in wdspec tests; r=ato+446296
MozReview-Commit-ID: zzIQgSgEPb --HG-- extra : rebase_source : 66f85d7042832b77c78d8bf64bfd06fe8522fe8f
This commit is contained in:
Родитель
40b28e28cc
Коммит
15062967d8
|
@ -6,6 +6,14 @@ def key_chain(session):
|
|||
return session.actions.sequence("key", "keyboard_id")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mouse_chain(session):
|
||||
return session.actions.sequence(
|
||||
"pointer",
|
||||
"pointer_id",
|
||||
{"pointerType": "mouse"})
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def release_actions(session, request):
|
||||
# release all actions after each test
|
||||
|
|
|
@ -1,21 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from support.keys import Keys
|
||||
from support.refine import get_keys, filter_dict
|
||||
|
||||
|
||||
def get_events(session):
|
||||
"""Return list of key events recorded in the test_keys_page fixture."""
|
||||
events = session.execute_script("return allEvents.events;") or []
|
||||
# `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in
|
||||
# test_keys_wdspec.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 e["key"].startswith(u"U+"):
|
||||
key = e["key"]
|
||||
hex_suffix = key[key.index("+") + 1:]
|
||||
e["key"] = unichr(int(hex_suffix, 16))
|
||||
return events
|
||||
from support.refine import get_keys, filter_dict, get_events
|
||||
|
||||
|
||||
def test_lone_keyup_sends_no_events(session, key_reporter, key_chain):
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import pytest
|
||||
from support.refine import get_events
|
||||
|
||||
def test_nothing():
|
||||
assert True
|
||||
|
||||
#def test_nothing(session, test_actions_page, mouse_chain):
|
||||
# mouse_chain \
|
||||
# .pointer_down(1) \
|
||||
# .perform()
|
||||
# assert True
|
||||
|
|
|
@ -1,18 +1,4 @@
|
|||
from support.refine import get_keys, filter_dict
|
||||
|
||||
|
||||
def get_events(session):
|
||||
"""Return list of key events recorded in the test_keys_page fixture."""
|
||||
events = session.execute_script("return allEvents.events;") or []
|
||||
# `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in
|
||||
# test_keys_wdspec.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 e["key"].startswith(u"U+"):
|
||||
key = e["key"]
|
||||
hex_suffix = key[key.index("+") + 1:]
|
||||
e["key"] = unichr(int(hex_suffix, 16))
|
||||
return events
|
||||
from support.refine import get_keys, filter_dict, get_events
|
||||
|
||||
|
||||
def test_no_actions_send_no_events(session, key_reporter, key_chain):
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
def get_events(session):
|
||||
"""Return list of key events recorded in the test_keys_page fixture."""
|
||||
events = session.execute_script("return allEvents.events;") or []
|
||||
# `key` values in `allEvents` may be escaped (see `escapeSurrogateHalf` in
|
||||
# test_keys_wdspec.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"] = unichr(int(hex_suffix, 16))
|
||||
return events
|
||||
|
||||
|
||||
def get_keys(input_el):
|
||||
"""Get printable characters entered into `input_el`.
|
||||
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<head>
|
||||
<title>Test Actions</title>
|
||||
<style>
|
||||
div { padding:0px; margin: 0px; }
|
||||
#resultContainer { width: 600px; height: 60px; }
|
||||
#outer { width: 100px; height: 50px; background-color: #ccc; }
|
||||
#trackPointer {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border: solid 1px red;
|
||||
position: fixed; }
|
||||
</style>
|
||||
<script>
|
||||
var allEvents = {events: []};
|
||||
function displayMessage(message) {
|
||||
|
@ -33,7 +42,7 @@
|
|||
return key;
|
||||
}
|
||||
|
||||
function recordEvent(event) {
|
||||
function recordKeyboardEvent(event) {
|
||||
var key = escapeSurrogateHalf(event.key);
|
||||
allEvents.events.push({
|
||||
"code": event.code,
|
||||
|
@ -46,25 +55,77 @@
|
|||
"repeat": event.repeat,
|
||||
"type": event.type
|
||||
});
|
||||
appendMessage(`${event.type}(code:${event.code}, key:${key}, which:${event.which})`);
|
||||
appendMessage(`${event.type}(` +
|
||||
`code: ${event.code}, ` +
|
||||
`key: ${key}, ` +
|
||||
`which: ${event.which})`);
|
||||
}
|
||||
|
||||
function recordPointerEvent(event) {
|
||||
allEvents.events.push({
|
||||
"type": event.type,
|
||||
"button": event.button,
|
||||
"buttons": event.buttons,
|
||||
"pageX": event.pageX,
|
||||
"pageY": event.pageY,
|
||||
"target": event.target.id
|
||||
});
|
||||
appendMessage(`${event.type}(` +
|
||||
`button: ${event.button}, ` +
|
||||
`pageX: ${event.pageX}, ` +
|
||||
`pageY: ${event.pageY}, ` +
|
||||
`button: ${event.button}, ` +
|
||||
`buttons: ${event.buttons}, ` +
|
||||
`target id: ${event.target.id})`);
|
||||
}
|
||||
|
||||
function recordFirstPointerMove(event) {
|
||||
recordPointerEvent(event);
|
||||
window.removeEventListener("mousemove", recordFirstPointerMove);
|
||||
}
|
||||
|
||||
function resetEvents() {
|
||||
allEvents.events.length = 0;
|
||||
displayMessage("");
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
var keyReporter = document.getElementById("keys");
|
||||
["keyup", "keypress", "keydown"].forEach((e) => {
|
||||
keyReporter.addEventListener(e, recordKeyboardEvent);
|
||||
});
|
||||
var outer = document.getElementById("outer");
|
||||
["click", "dblclick", "mousedown",
|
||||
"mouseup", "contextmenu"].forEach((e) => {
|
||||
outer.addEventListener(e, recordPointerEvent);
|
||||
});
|
||||
window.addEventListener("mousemove", recordFirstPointerMove);
|
||||
//visual cue for mousemove
|
||||
var pointer = document.getElementById("trackPointer");
|
||||
window.addEventListener("mousemove", (e) => {
|
||||
setTimeout(() => {
|
||||
let offset = 15;
|
||||
pointer.style.top = e.pageY + offset + "px";
|
||||
pointer.style.left = e.pageX + offset + "px";
|
||||
}, 30);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="trackPointer"></div>
|
||||
<div>
|
||||
<h2>KeyReporter</h2>
|
||||
<input type="text" id="keys" size="80"
|
||||
onkeyup="recordEvent(event)"
|
||||
onkeypress="recordEvent(event)"
|
||||
onkeydown="recordEvent(event)">
|
||||
<input type="text" id="keys" size="80">
|
||||
</div>
|
||||
<div id="resultContainer" style="width:300;height:60">
|
||||
<div>
|
||||
<h2>ClickReporter</h2>
|
||||
<div id="outer">
|
||||
</div>
|
||||
</div>
|
||||
<div id="resultContainer">
|
||||
<h2>Events</h2>
|
||||
<div id="events"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Загрузка…
Ссылка в новой задаче