Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /editing/other/fire-selection-change-on-deleting-empty-element.html - WPT Dashboard Interop Dashboard
<!doctype HTML>
<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>
<body>
<div contenteditable="true" id="target"></div>
<script>
// Selection should be updated when removing element in contenteditable div
promise_test(async () => {
const target = document.getElementById("target");
const backSpaceKey = "\uE003";
target.innerHTML = "<h1>A</h1>";
let selectionChangeCount = 0;
await new test_driver.click(target);
// Waits a short time to allow any events to be processed.
await new Promise(resolve => step_timeout(resolve, 500));
await new test_driver.send_keys(target, backSpaceKey);
// Waits a short time to process all selectionchange events currently in the queue.
await new Promise(resolve => step_timeout(resolve, 500));
const expectedHTML = "<h1><br></h1>";
assert_equals(target.innerHTML, expectedHTML, "Character should be removed");
document.addEventListener("selectionchange", () => ++selectionChangeCount);
// Remove the <h1> element
await new test_driver.send_keys(target, backSpaceKey);
// Waits a short time to process all selectionchange events currently in the queue.
await new Promise(resolve => step_timeout(resolve, 500));
assert_equals(selectionChangeCount, 1, "Selection change count should match");
}, "Selection is updated after removing the element in contenteditable div");
</script>
</body>