Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

  • This WPT test may be referenced by the following Test IDs:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pasting text to editing host which tries to remove all inserted nodes shouldn't cause hangup</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>
<script src="/resources/testdriver-actions.js"></script>
<script src="../include/editor-test-utils.js"></script>
<script>
"use strict";
document.addEventListener("DOMContentLoaded", () => {
const copyTextContainer = document.querySelector("p");
const editingHost = document.querySelector("div[contenteditable]");
const utils = new EditorTestUtils(editingHost);
editingHost.addEventListener("paste", () => {
const fragment = document.createDocumentFragment();
let child;
while ((child = editingHost.childNodes[1])) {
fragment.appendChild(child);
}
});
promise_test(async () => {
copyTextContainer.innerHTML = "XYZ";
await test_driver.click(copyTextContainer);
getSelection().selectAllChildren(copyTextContainer);
await utils.sendCopyShortcutKey();
utils.setupEditingHost("abc def []<br>");
await utils.sendPasteShortcutKey();
assert_true(true); // Don't timeout
}, "Pasting text ends with a visible character");
promise_test(async () => {
copyTextContainer.innerHTML = "XYZ X";
await test_driver.click(copyTextContainer);
getSelection().setBaseAndExtent(
copyTextContainer.firstChild,
0,
copyTextContainer.firstChild,
"XYZ ".length
);
await utils.sendCopyShortcutKey();
utils.setupEditingHost("abc def []<br>");
await utils.sendPasteShortcutKey();
assert_true(true); // Don't timeout
}, "Pasting text ends with a collapsible white-space");
}, {once: true});
</script>
</head>
<body>
<p></p>
<div contenteditable></div>
</body>
</html>