Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long">
<meta name="variant" content="?action=Backspace">
<meta name="variant" content="?action=Delete">
<title>Delete in last list item should not delete parent list if it's editing host</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 params = new URLSearchParams(location.search.substring(1));
const backspace = params.get("action") == "Backspace";
addEventListener("load", () => {
document.body.innerHTML ="<dl contenteditable></dl>";
const editingHost = document.querySelector("dl[contenteditable]");
const utils = new EditorTestUtils(editingHost);
function addPromiseTest(aTest) {
promise_test(async () => {
editingHost.focus();
utils.setupEditingHost(aTest.innerHTML);
await (backspace ? utils.sendBackspaceKey() : utils.sendDeleteKey());
utils.normalizeStyleAttributeValues();
if (Array.isArray(aTest.expectedResult)) {
assert_in_array(editingHost.innerHTML, aTest.expectedResult);
} else {
assert_equals(editingHost.innerHTML, aTest.expectedResult);
}
assert_equals(
document.body.childNodes.length,
1,
`The editing host should be the only child of <body> (got: "${document.body.innerHTML}")`
);
assert_equals(
document.body.firstChild,
editingHost,
`The editing host should be the only child of <body> (got: "${document.body.innerHTML}")`
);
}, `${backspace ? "Backspace" : "Delete"} in "<dl contenteditable>${aTest.innerHTML}</dl>"`);
}
addPromiseTest({
innerHTML: "<dt>{}</dt>",
expectedResult: ["<dt></dt>", "<dt><br></dt>"],
});
addPromiseTest({
innerHTML: "<dd>{}</dd>",
expectedResult: ["<dd></dd>", "<dd><br></dd>"],
});
addPromiseTest({
innerHTML: "<dd><ul><li>{}</li></ul></dd>",
expectedResult: ["<dd></dd>", "<dd><br></dd>"],
});
addPromiseTest({
innerHTML: "<dd><ol><li>{}</li></ol></dd>",
expectedResult: ["<dd></dd>", "<dd><br></dd>"],
});
// If only sub-list in the editing host list element, the sub-list should be
// replaced with a list item.
addPromiseTest({
innerHTML: "<ul><li>{}</li></ul>",
expectedResult: ["<dd></dd>", "<dd><br></dd>"],
});
addPromiseTest({
innerHTML: "<ol><li>{}</li></ol>",
expectedResult: ["<dd></dd>", "<dd><br></dd>"],
});
addPromiseTest({
innerHTML: "<dl><dt>{}</dt></dl>",
expectedResult: ["<dd></dd>", "<dd><br></dd>"],
});
addPromiseTest({
innerHTML: "<dl><dd>{}</dd></dl>",
expectedResult: ["<dd></dd>", "<dd><br></dd>"],
});
}, {once:true});
</script>
</head>
<body></body>
</html>