diff options
Diffstat (limited to 'testing/web-platform/tests/uievents/textInput/support/common.js')
-rw-r--r-- | testing/web-platform/tests/uievents/textInput/support/common.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/testing/web-platform/tests/uievents/textInput/support/common.js b/testing/web-platform/tests/uievents/textInput/support/common.js new file mode 100644 index 0000000000..25c39da3e2 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/support/common.js @@ -0,0 +1,38 @@ +function elDesc(el) { + let rv = `<${el.localName}`; + if (el.hasAttribute('contenteditable')) { + rv += ` contenteditable="${el.getAttribute('contenteditable')}"`; + } + if (el.hasAttribute('type')) { + rv += ` type="${el.getAttribute('type')}"`; + } + rv += `>`; + return rv; +} + +function setSelection(el, selectionStart, selectionEnd) { + if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) { + el.selectionStart = selectionStart; + el.selectionEnd = selectionEnd; + } else { + const s = getSelection(); + s.removeAllRanges(); + const r = new Range(); + r.setStart(el.firstChild || el, selectionStart); + r.setEnd(el.firstChild || el, selectionEnd); + s.addRange(r); + } +} + +function getValue(el) { + if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) { + return el.value; + } + return el.innerHTML; +} + +const keyMapping = { + "Enter": "\uE006", + "Backspace": "\uE003", + "Delete": "\uE017", +}; |