From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../web-platform/tests/uievents/textInput/api.html | 88 ++++++++++++++++++++++ .../tests/uievents/textInput/backspace.html | 16 ++++ .../tests/uievents/textInput/basic.html | 16 ++++ .../tests/uievents/textInput/delete-selection.html | 16 ++++ .../tests/uievents/textInput/delete.html | 16 ++++ .../tests/uievents/textInput/enter-input.html | 14 ++++ .../textInput/enter-textarea-contenteditable.html | 15 ++++ .../tests/uievents/textInput/smiley-manual.html | 17 +++++ .../tests/uievents/textInput/support/basic.sub.js | 49 ++++++++++++ .../tests/uievents/textInput/support/common.js | 38 ++++++++++ .../uievents/textInput/support/no-textInput.sub.js | 29 +++++++ 11 files changed, 314 insertions(+) create mode 100644 testing/web-platform/tests/uievents/textInput/api.html create mode 100644 testing/web-platform/tests/uievents/textInput/backspace.html create mode 100644 testing/web-platform/tests/uievents/textInput/basic.html create mode 100644 testing/web-platform/tests/uievents/textInput/delete-selection.html create mode 100644 testing/web-platform/tests/uievents/textInput/delete.html create mode 100644 testing/web-platform/tests/uievents/textInput/enter-input.html create mode 100644 testing/web-platform/tests/uievents/textInput/enter-textarea-contenteditable.html create mode 100644 testing/web-platform/tests/uievents/textInput/smiley-manual.html create mode 100644 testing/web-platform/tests/uievents/textInput/support/basic.sub.js create mode 100644 testing/web-platform/tests/uievents/textInput/support/common.js create mode 100644 testing/web-platform/tests/uievents/textInput/support/no-textInput.sub.js (limited to 'testing/web-platform/tests/uievents/textInput') diff --git a/testing/web-platform/tests/uievents/textInput/api.html b/testing/web-platform/tests/uievents/textInput/api.html new file mode 100644 index 0000000000..a88184e500 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/api.html @@ -0,0 +1,88 @@ + + +textInput: API + + + + +
+ + diff --git a/testing/web-platform/tests/uievents/textInput/backspace.html b/testing/web-platform/tests/uievents/textInput/backspace.html new file mode 100644 index 0000000000..c9b2f8bee4 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/backspace.html @@ -0,0 +1,16 @@ + + +textInput: backspace + + + + + +

Press Backspace in each text field below.

+ + +
abc
+ + diff --git a/testing/web-platform/tests/uievents/textInput/basic.html b/testing/web-platform/tests/uievents/textInput/basic.html new file mode 100644 index 0000000000..6335167faa --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/basic.html @@ -0,0 +1,16 @@ + + +textInput: basic + + + + + +

Type "a" into each text field below.

+ + +
+ + diff --git a/testing/web-platform/tests/uievents/textInput/delete-selection.html b/testing/web-platform/tests/uievents/textInput/delete-selection.html new file mode 100644 index 0000000000..f77e8c6e98 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/delete-selection.html @@ -0,0 +1,16 @@ + + +textInput: delete selection + + + + + +

Press Delete (Fn+Backspace for macOS) in each text field below.

+ + +
abc
+ + diff --git a/testing/web-platform/tests/uievents/textInput/delete.html b/testing/web-platform/tests/uievents/textInput/delete.html new file mode 100644 index 0000000000..2d696fba71 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/delete.html @@ -0,0 +1,16 @@ + + +textInput: delete + + + + + +

Press Delete (Fn+Backspace for macOS) in each text field below.

+ + +
abc
+ + diff --git a/testing/web-platform/tests/uievents/textInput/enter-input.html b/testing/web-platform/tests/uievents/textInput/enter-input.html new file mode 100644 index 0000000000..032503694d --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/enter-input.html @@ -0,0 +1,14 @@ + + +textInput: Enter key for input element + + + + + +

Press Enter in the text field below.

+ + + diff --git a/testing/web-platform/tests/uievents/textInput/enter-textarea-contenteditable.html b/testing/web-platform/tests/uievents/textInput/enter-textarea-contenteditable.html new file mode 100644 index 0000000000..60891df982 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/enter-textarea-contenteditable.html @@ -0,0 +1,15 @@ + + +textInput: Enter key for textarea and contenteditable + + + + + +

Press Enter in each text field below.

+ +
+ + diff --git a/testing/web-platform/tests/uievents/textInput/smiley-manual.html b/testing/web-platform/tests/uievents/textInput/smiley-manual.html new file mode 100644 index 0000000000..7781f6e1b0 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/smiley-manual.html @@ -0,0 +1,17 @@ + + +textInput: smiley (manual) + + + +

Type "🙂" into each text field below.

+ + +
+ + + diff --git a/testing/web-platform/tests/uievents/textInput/support/basic.sub.js b/testing/web-platform/tests/uievents/textInput/support/basic.sub.js new file mode 100644 index 0000000000..55d2f0d1e6 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/support/basic.sub.js @@ -0,0 +1,49 @@ +const els = document.querySelectorAll('.test-el'); +const key = "{{GET[key]}}"; +const keyRaw = keyMapping[key] || key; +const expectedData = key === "Enter" ? "\n" : key; +const selectionStart = {{GET[selectionStart]}}; +const selectionEnd = {{GET[selectionEnd]}}; +const expectedValue = "{{GET[expectedValue]}}"; + +for (const el of els) { + promise_test(t => { + return new Promise((resolve, reject) => { + let beforeinputEvents = 0; + let textInputEvents = 0; + el.addEventListener('beforeinput', t.step_func(e => { + beforeinputEvents++; + })); + el.addEventListener('textInput', t.step_func(e => { + textInputEvents++; + assert_equals(beforeinputEvents, 1); + assert_equals(e.data, expectedData); + assert_true(e.bubbles); + assert_true(e.cancelable); + assert_equals(e.view, window); + assert_equals(e.detail, 0); + assert_true(e instanceof window.TextEvent); + })); + el.addEventListener('input', t.step_func(e => { + assert_equals(textInputEvents, 1); + if (expectedValue === "\n" && !(el instanceof HTMLInputElement) && !(el instanceof HTMLTextAreaElement)) { + // New paragraph in contenteditable during editing is weird. + // innerHTML is


+ // ...but later changes to
+ // So, check that there's at least one
. + assert_true(getValue(el).indexOf('
') > -1); + } else { + assert_equals(getValue(el), expectedValue); + } + resolve(); + })); + el.onfocus = t.step_func(e => { + if (window.test_driver) { + test_driver.send_keys(el, keyRaw); + } + }); + el.focus(); + setSelection(el, selectionStart, selectionEnd); + }); + }, `${document.title}, ${elDesc(el)}`); +} 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", +}; diff --git a/testing/web-platform/tests/uievents/textInput/support/no-textInput.sub.js b/testing/web-platform/tests/uievents/textInput/support/no-textInput.sub.js new file mode 100644 index 0000000000..332cbf08f2 --- /dev/null +++ b/testing/web-platform/tests/uievents/textInput/support/no-textInput.sub.js @@ -0,0 +1,29 @@ +const els = document.querySelectorAll('.test-el'); +const key = "{{GET[key]}}"; +const keyRaw = keyMapping[key] || key; +const expectedData = key === "Enter" ? "\n" : key; +const selectionStart = {{GET[selectionStart]}}; +const selectionEnd = {{GET[selectionEnd]}}; +const expectedValue = "{{GET[expectedValue]}}"; + +for (const el of els) { + promise_test(t => { + return new Promise((resolve, reject) => { + el.addEventListener('textInput', reject); + el.addEventListener('keyup', t.step_func(e => { + if (e.key !== key) { + return; + } + assert_equals(getValue(el), expectedValue); + resolve(); + })); + el.onfocus = t.step_func(e => { + if (window.test_driver) { + test_driver.send_keys(el, keyRaw); + } + }); + el.focus(); + setSelection(el, selectionStart, selectionEnd); + }); + }, `${document.title}, ${elDesc(el)}`); +} -- cgit v1.2.3