Automatic update from web-platform-tests [Editing] Fire selectionchange event on TextControl for backspace input The selectionchange event does not get fired when the backspace key deletes text inside a textcontrol element. According to the specification [1], when an input or textarea element provide a text selection and its selection changes (in either extent or direction), the user agent must schedule a selectionchange event on the element. This change ensures that the event will be scheduled as per the specification. [1] https://w3c.github.io/selection-api/#selectionchange-event Bug: 41321247 Change-Id: Id6307b9baaee6480ba607ae8576959e2635e7b16 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6012498 Commit-Queue: Tanu Jain <tanujain@microsoft.com> Reviewed-by: Siye Liu <siliu@microsoft.com> Reviewed-by: Kent Tamura <tkent@chromium.org> Cr-Commit-Position: refs/heads/main@{#1388005} -- wpt-commits: 020db3e4207abe0e7b45ec5f1730d01b4ed2cf1e wpt-pr: 49363
47 lines
1.8 KiB
HTML
47 lines
1.8 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8">
|
|
<title>Test selectionchange event fired on Text Control element</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/resources/testdriver.js"></script>
|
|
<script src="/resources/testdriver-vendor.js"></script>
|
|
|
|
<input id="input" type="text" value="hello">
|
|
|
|
<script>
|
|
const element = document.querySelector("input");
|
|
const events_on_document = [];
|
|
document.addEventListener("selectionchange", ev => {
|
|
events_on_document.push(ev);
|
|
});
|
|
|
|
const events_on_input = [];
|
|
element.addEventListener("selectionchange", ev => {
|
|
events_on_input.push(ev);
|
|
});
|
|
|
|
promise_test(async () => {
|
|
element.focus();
|
|
element.setSelectionRange(5, 5);
|
|
await new Promise(resolve => step_timeout(resolve, 500));
|
|
events_on_document.length = 0;
|
|
events_on_input.length = 0;
|
|
|
|
assert_equals(element.selectionStart, 5, "selectionStart before pressing backspace key");
|
|
assert_equals(element.selectionEnd, 5, "selectionEnd before pressing backspace key");
|
|
|
|
await new test_driver.send_keys(element, "\uE003");
|
|
|
|
assert_equals(element.selectionStart, 4, "selectionStart after pressing backspace key");
|
|
assert_equals(element.selectionEnd, 4, "selectionEnd after pressing backspace key");
|
|
|
|
// Waits a short time to allow any events to be processed.
|
|
await new Promise(resolve => step_timeout(resolve, 500));
|
|
assert_equals(events_on_input.length, 1);
|
|
|
|
//selectionchange event fired on a text control should bubble to the document
|
|
assert_equals(events_on_document[0].target, element, "Event target should be the input element");
|
|
assert_equals(events_on_document.length, 1);
|
|
|
|
}, "selectionchange event fired on an input element");
|
|
</script> |