Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long">
<meta name="variant" content="?white-space=normal">
<meta name="variant" content="?white-space=pre">
<meta name="variant" content="?white-space=pre-line">
<meta name="variant" content="?white-space=pre-wrap">
<title>Deleting content immediately before invisible line break should clean up if it's unnecessary anymore</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";
const searchParams = new URLSearchParams(document.location.search);
const whiteSpace = searchParams.get("white-space");
const useBR = whiteSpace == "normal";
const collapseWhiteSpaces = whiteSpace == "normal" || whiteSpace == "pre-line";
addEventListener("load", () => {
const editingHost = document.querySelector("div[contenteditable]");
editingHost.style.whiteSpace = whiteSpace;
editingHost.getBoundingClientRect();
editingHost.focus();
const utils = new EditorTestUtils(editingHost);
for (const data of [
{
initialInnerHTML: "<p>a []<br></p>",
expected: "<p>a</p>",
},
{
initialInnerHTML: "<p>a[ ]<br></p>",
expected: "<p>a</p>",
},
{
initialInnerHTML: "<p>a b[]<br></p>",
expected: collapseWhiteSpaces
? (useBR ? ["<p>a <br></p>", "<p>a&nbsp;</p>"] : ["<p>a <br></p>", "<p>a \n</p>", "<p>a&nbsp;</p>"])
: "<p>a </p>",
},
{
initialInnerHTML: "<p>a [b]<br></p>",
expected: collapseWhiteSpaces
? (useBR ? ["<p>a <br></p>", "<p>a&nbsp;</p>"] : ["<p>a <br></p>", "<p>a \n</p>", "<p>a&nbsp;</p>"])
: "<p>a </p>",
},
{
initialInnerHTML: "<p>a []\n</p>",
expected: "<p>a</p>",
skipIf: () => useBR,
},
{
initialInnerHTML: "<p>a[ ]\n</p>",
expected: "<p>a</p>",
skipIf: () => useBR,
},
{
initialInnerHTML: "<p>a b[]\n</p>",
expected: collapseWhiteSpaces
? ["<p>a \n</p>", "<p>a&nbsp;</p>"]
: "<p>a </p>",
skipIf: () => useBR,
},
{
initialInnerHTML: "<p>a [b]\n</p>",
expected: collapseWhiteSpaces
? ["<p>a \n</p>", "<p>a&nbsp;</p>"]
: "<p>a </p>",
skipIf: () => useBR,
},
{
initialInnerHTML: "<div>a []<br><div>b</div></div>",
expected: "<div>a<div>b</div></div>",
},
{
initialInnerHTML: "<div>a[ ]<br><div>b</div></div>",
expected: "<div>a<div>b</div></div>",
},
{
initialInnerHTML: "<div>a b[]<br><div>b</div></div>",
expected: collapseWhiteSpaces
? (useBR
? ["<div>a <br><div>b</div></div>", "<div>a&nbsp;<div>b</div></div>"]
: ["<div>a <br><div>b</div></div>", "<div>a \n<div>b</div></div>", "<div>a&nbsp;<div>b</div></div>"])
: "<div>a <div>b</div></div>",
},
{
initialInnerHTML: "<div>a [b]<br><div>b</div></div>",
expected: collapseWhiteSpaces
? (useBR
? ["<div>a <br><div>b</div></div>", "<div>a&nbsp;<div>b</div></div>"]
: ["<div>a <br><div>b</div></div>", "<div>a \n<div>b</div></div>", "<div>a&nbsp;<div>b</div></div>"])
: "<div>a <div>b</div></div>",
},
{
initialInnerHTML: "<div>a []\n<div>b</div></div>",
expected: "<div>a<div>b</div></div>",
skipIf: () => useBR,
},
{
initialInnerHTML: "<div>a[ ]\n<div>b</div></div>",
expected: "<div>a<div>b</div></div>",
skipIf: () => useBR,
},
{
initialInnerHTML: "<div>a b[]\n<div>b</div></div>",
expected: collapseWhiteSpaces
? ["<div>a \n<div>b</div></div>", "<div>a&nbsp;<div>b</div></div>"]
: "<div>a <div>b</div></div>",
skipIf: () => useBR,
},
{
initialInnerHTML: "<div>a [b]\n<div>b</div></div>",
expected: collapseWhiteSpaces
? ["<div>a \n<div>b</div></div>", "<div>a&nbsp;<div>b</div></div>"]
: "<div>a <div>b</div></div>",
skipIf: () => useBR,
},
]) {
if (data.skipIf !== undefined && data.skipIf()) {
continue;
}
promise_test(async () => {
utils.setupEditingHost(data.initialInnerHTML);
document.execCommand("delete");
if (Array.isArray(data.expected)) {
assert_in_array(editingHost.innerHTML, data.expected);
} else {
assert_equals(editingHost.innerHTML, data.expected);
}
}, `document.execCommand("delete") when ${data.initialInnerHTML.replaceAll("\n", "\\n")}`);
promise_test(async () => {
utils.setupEditingHost(data.initialInnerHTML);
await utils.sendBackspaceKey();
if (Array.isArray(data.expected)) {
assert_in_array(editingHost.innerHTML, data.expected);
} else {
assert_equals(editingHost.innerHTML, data.expected);
}
}, `Backspace when ${data.initialInnerHTML.replaceAll("\n", "\\n")}`);
}
}, {once: true});
</script>
</head>
<body>
<div contenteditable></div>
</body>
</html>