blob: 54396320303cbe03fa2e81aa99565f09a36c6fc6 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description">This test checks that deletion does not leave unnecessary nested divs.</p>
<div id="console"></div>
<script>
var sel = document.getSelection();
var root = document.createElement("root");
document.body.appendChild(root);
function createEditable(tagName, markup) {
var node = document.createElement(tagName);
node.contentEditable = true;
node.innerHTML = markup;
return node;
}
function testDelete(tagName, originalMarkup, expected) {
var node = createEditable(tagName, originalMarkup);
root.appendChild(node);
node.focus();
document.execCommand("SelectAll", false);
document.execCommand("Delete", false);
confirmedMarkup = node.innerHTML;
shouldBe("confirmedMarkup", "'" + expected + "'");
}
testDelete("div", "Hello", "<br>");
testDelete("div", "<div>Hello</div>", "<br>");
testDelete("div", "<div id=\"mydiv\">Hello</div>", "<div id=\"mydiv\"><br></div>");
testDelete("div", "<div><div>Hello</div></div>", "<br>");
testDelete("div", "<div><b><div><i>Hello</i></div></b></div>", "<b><br></b>");
testDelete("div", "<div><b><div style=\"border: solid red\"><i>Hello</i></div></b></div>", "<b><div style=\"border: solid red\"><br></div></b>");
testDelete("div", "<div>Hello</div><div>world</div>", "<br>");
testDelete("div", "<div>Hello</div><div>world</div>", "<br>");
testDelete("div", "<div><p>Hello</p></div><p>world</p></div>", "<p><br></p>");
root.style.display = "none";
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>