Skip to content

Commit

Permalink
Add automated tests of insertParagraph and insertLineBreak insert…
Browse files Browse the repository at this point in the history
…s 2 line breaks at end of `<span contenteditable>` if it's followed by a `<div>` (#41036)

`insertParagraph` and `insertLineBreak` at
`<span contenteditable>foo[]</span><div>bar</div>` requires 2 line
breaks to make the last empty line visible.  This changeset adds the
tests.

Fixes web-platform-tests/interop#368
  • Loading branch information
masayuki-nakano authored Oct 12, 2023
1 parent 7c2914d commit eea2d9d
Showing 1 changed file with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,49 @@
defaultParagraphSeparator
})`);

promise_test(async t => {
editingHost.setAttribute(
"style",
`display:${display};white-space:${whiteSpace}`
);
const divElement = document.createElement("div");
divElement.textContent = "efg";
try {
container.appendChild(divElement);
utils.setupEditingHost("{}");
await utils.sendEnterKey(modifiers);
editingHost.removeAttribute("style");
// When the <span> element is followed by a <div>, making empty last
// line visible requires an invisible <br> after a line break.
if (!isPreformatted) {
assert_equals(
container.innerHTML,
'<span contenteditable=""><br><br></span><div>efg</div>',
`A <br> and additional <br> should be inserted when ${t.name}`
);
} else {
assert_in_array(
container.innerHTML,
[
`<span contenteditable="">\n\n</span><div>efg</div>`,
`<span contenteditable="">\n<br></span><div>efg</div>`,
],
`A linefeed and additional line break should be inserted when ${t.name}`
);
}
} finally {
divElement.remove();
}
}, `${
testingInsertParagraph ? "insertParagraph" : "insertLineBreak"
} in <span contenteditable style="display:${
display
};white-space:${
whiteSpace
}">{}</span> followed by a <div> (defaultParagraphSeparator=${
defaultParagraphSeparator
})`);

promise_test(async t => {
editingHost.setAttribute(
"style",
Expand Down Expand Up @@ -369,6 +412,49 @@
defaultParagraphSeparator
})`);

promise_test(async t => {
editingHost.setAttribute(
"style",
`display:${display};white-space:${whiteSpace}`
);
const divElement = document.createElement("div");
divElement.textContent = "efg";
try {
container.appendChild(divElement);
utils.setupEditingHost("abcd[]");
await utils.sendEnterKey(modifiers);
editingHost.removeAttribute("style");
// When the <span> element is followed by a <div>, making empty last
// line visible requires an invisible <br> after a line break.
if (!isPreformatted) {
assert_equals(
container.innerHTML,
'<span contenteditable="">abcd<br><br></span><div>efg</div>',
`A <br> and additional <br> should be inserted when ${t.name}`
);
} else {
assert_in_array(
container.innerHTML,
[
`<span contenteditable="">abcd\n<br></span><div>efg</div>`,
`<span contenteditable="">abcd\n\n</span><div>efg</div>`,
],
`A linefeed and additional line break should be inserted when ${t.name}`
);
}
} finally {
divElement.remove();
}
}, `${
testingInsertParagraph ? "insertParagraph" : "insertLineBreak"
} in <span contenteditable style="display:${
display
};white-space:${
whiteSpace
}">abcd[]</span> followed by a <div> element (defaultParagraphSeparator=${
defaultParagraphSeparator
})`);

promise_test(async t => {
editingHost.setAttribute(
"style",
Expand Down

0 comments on commit eea2d9d

Please sign in to comment.