97 lines
3.4 KiB
HTML
97 lines
3.4 KiB
HTML
<!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>excCommand("insertParagraph") in plaintext-only</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.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";
|
|
|
|
addEventListener("load", () => {
|
|
const editingHost = document.createElement("div");
|
|
editingHost.style.whiteSpace = whiteSpace;
|
|
editingHost.setAttribute("contenteditable", "plaintext-only");
|
|
document.body.appendChild(editingHost);
|
|
editingHost.focus();
|
|
editingHost.getBoundingClientRect();
|
|
const utils = new EditorTestUtils(editingHost);
|
|
|
|
/**
|
|
* insertParagraph command in plaintext-only is available only with document.execCommand.
|
|
* It should work as same as contenteditable=true, therefore, this test checks only
|
|
* basic behavior. Various edge cases should be tested in run/insertparagraph.html.
|
|
*
|
|
* Currently, <br> is used for padding line break in empty paragraph. This won't appear
|
|
* in `.textContent` of the editing host, but the paragraph itself does not appear in
|
|
* the value too. Therefore, web apps anyway need to use `.innerHTML` to get the result.
|
|
* So, using <br> should not be a problem for web apps.
|
|
*/
|
|
|
|
for (const data of [
|
|
{
|
|
initialInnerHTML: "<p>[]AB</p>",
|
|
expected: "<p><br></p><p>AB</p>",
|
|
},
|
|
{
|
|
initialInnerHTML: "<p>A[]B</p>",
|
|
expected: "<p>A</p><p>B</p>",
|
|
},
|
|
{
|
|
initialInnerHTML: "<p>AB[]</p>",
|
|
expected: "<p>AB</p><p><br></p>",
|
|
},
|
|
{
|
|
initialInnerHTML: `<p style="white-space:normal">[]AB</p>`,
|
|
expected: `<p style="white-space:normal"><br></p><p style="white-space:normal">AB</p>`,
|
|
},
|
|
{
|
|
initialInnerHTML: `<p style="white-space:pre">[]AB</p>`,
|
|
expected: `<p style="white-space:pre"><br></p><p style="white-space:pre">AB</p>`,
|
|
},
|
|
{
|
|
initialInnerHTML: `<p style="white-space:pre-line">[]AB</p>`,
|
|
expected: `<p style="white-space:pre-line"><br></p><p style="white-space:pre-line">AB</p>`,
|
|
},
|
|
{
|
|
initialInnerHTML: `<p style="white-space:pre-wrap">[]AB</p>`,
|
|
expected: `<p style="white-space:pre-wrap"><br></p><p style="white-space:pre-wrap">AB</p>`,
|
|
},
|
|
{
|
|
initialInnerHTML: "<ul><li>[]AB</li></ul>",
|
|
expected: "<ul><li><br></li><li>AB</li></ul>",
|
|
},
|
|
{
|
|
initialInnerHTML: "<ul><li>A[]B</li></ul>",
|
|
expected: "<ul><li>A</li><li>B</li></ul>",
|
|
},
|
|
{
|
|
initialInnerHTML: "<ul><li>AB[]</li></ul>",
|
|
expected: "<ul><li>AB</li><li><br></li></ul>",
|
|
},
|
|
]) {
|
|
test(() => {
|
|
utils.setupEditingHost(data.initialInnerHTML);
|
|
document.execCommand("insertParagraph");
|
|
if (Array.isArray(data.expected)) {
|
|
assert_in_array(editingHost.innerHTML, data.expected);
|
|
} else {
|
|
assert_equals(editingHost.innerHTML, data.expected);
|
|
}
|
|
}, `execCommand("insertParagraph") when ${data.initialInnerHTML}`);
|
|
}
|
|
}, {once: true});
|
|
</script>
|
|
</head>
|
|
<body></body>
|
|
</html>
|