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.7 KiB
HTML
47 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8">
|
|
<title>Selectionchange event fired on document if TextControl element is in Shadow Tree</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
|
|
<div id="root"></div>
|
|
|
|
<script>
|
|
const root = document.getElementById("root");
|
|
const shadow = root.attachShadow({ mode: "open" });
|
|
const element = document.createElement("input");
|
|
element.value = "hello";
|
|
shadow.append(element);
|
|
|
|
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;
|
|
|
|
document.execCommand("delete");
|
|
// Waits a short time to allow any events to be processed.
|
|
await new Promise(resolve => step_timeout(resolve, 500));
|
|
|
|
const expectedValue = "hell";
|
|
assert_equals(element.value, expectedValue, "element.value should be " + expectedValue);
|
|
//selectionchange event should not fire on input element
|
|
assert_equals(events_on_input.length, 0);
|
|
|
|
//selectionchange event should fire on the document
|
|
assert_equals(events_on_document.length, 1);
|
|
assert_equals(events_on_document[0].target, document, "Event target should be the document");
|
|
|
|
}, "selectionchange event fired on the document in case TextControl element is in Shadow Tree");
|
|
</script> |