Skip to content

Commit

Permalink
part 8: Update WPT result and add new tests to insert mulitple white-…
Browse files Browse the repository at this point in the history
…spaces

This does NOT add tests to `inserttext` command which includes linefeed
characters with other characters.  It seems that Blink handles 2 or more
length string is handled as multiple calls for every character.  So each
linefeed character is handled as `insertparagraph`, but Gecko treats the
linefeed characters as-is.  We should add the tests later with changing
Gecko's behavior, but for now, we should keep current behavior because
this difference must not be trobule in the wild, but we need to improve
preformatted string handler of Gecko better against reported web-compat
issues.

Differential Revision: https://phabricator.services.mozilla.com/D124562

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1724650
gecko-commit: a26a1ab449955410e34e333fab81acb785e963f5
gecko-reviewers: m_kato
  • Loading branch information
masayuki-nakano authored and moz-wptsync-bot committed Sep 10, 2021
1 parent cc0f610 commit 5060914
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 19 deletions.
64 changes: 64 additions & 0 deletions editing/data/inserttext.js
Original file line number Diff line number Diff line change
Expand Up @@ -1279,4 +1279,68 @@ var browserTests = [
"<div contenteditable=\"false\"><span contenteditable=\"\">abcd<br></span></div>"],
[true],
{"inserttext":[false,false,"",false,false,""]}],
["<div style=white-space:pre>foo[]bar</div>",
[["inserttext"," "]],
"<div style=\"white-space:pre\">foo bar</div>",
[true],
{"inserttext":[false,false,"",false,false,""]}],
["<div style=white-space:pre>foo[]</div>",
[["inserttext"," "]],
"<div style=\"white-space:pre\">foo </div>",
[true],
{"inserttext":[false,false,"",false,false,""]}],
["<div style=white-space:pre-wrap>foo[]bar</div>",
[["inserttext"," "]],
"<div style=\"white-space:pre-wrap\">foo bar</div>",
[true],
{"inserttext":[false,false,"",false,false,""]}],
["<div style=white-space:pre-wrap>foo[]</div>",
[["inserttext"," "]],
"<div style=\"white-space:pre-wrap\">foo </div>",
[true],
{"inserttext":[false,false,"",false,false,""]}],
// FYI: The white-space sequence different does not matter here. It's tested
// in white-spaces-after-execCommand-inserttext.tentative.html.
["<div style=white-space:pre-line>foo[]bar</div>",
[["inserttext"," "]],
[
"<div style=\"white-space:pre-line\">foo &nbsp; &nbsp;bar</div>",
"<div style=\"white-space:pre-line\">foo&nbsp; &nbsp; bar</div>",
"<div style=\"white-space:pre-line\">foo&nbsp;&nbsp;&nbsp; bar</div>",
],
[true],
{"inserttext":[false,false,"",false,false,""]}],
["<div style=white-space:pre-line>foo[]</div>",
[["inserttext"," "]],
[
"<div style=\"white-space:pre-line\">foo &nbsp; &nbsp;</div>",
"<div style=\"white-space:pre-line\">foo&nbsp; &nbsp;&nbsp;</div>",
"<div style=\"white-space:pre-line\">foo&nbsp; &nbsp; \n</div>",
"<div style=\"white-space:pre-line\">foo&nbsp;&nbsp;&nbsp; \n</div>",
"<div style=\"white-space:pre-line\">foo&nbsp; &nbsp; <br></div>",
"<div style=\"white-space:pre-line\">foo&nbsp;&nbsp;&nbsp; <br></div>",
],
[true],
{"inserttext":[false,false,"",false,false,""]}],
["<div style=white-space:nowrap>foo[]bar</div>",
[["inserttext"," "]],
[
"<div style=\"white-space:nowrap\">foo &nbsp; &nbsp;bar</div>",
"<div style=\"white-space:nowrap\">foo&nbsp; &nbsp; bar</div>",
"<div style=\"white-space:nowrap\">foo&nbsp;&nbsp;&nbsp; bar</div>",
],
[true],
{"inserttext":[false,false,"",false,false,""]}],
["<div style=white-space:nowrap>foo[]</div>",
[["inserttext"," "]],
[
"<div style=\"white-space:nowrap\">foo &nbsp; &nbsp;</div>",
"<div style=\"white-space:nowrap\">foo&nbsp; &nbsp;&nbsp;</div>",
"<div style=\"white-space:nowrap\">foo&nbsp; &nbsp; \n</div>",
"<div style=\"white-space:nowrap\">foo&nbsp;&nbsp;&nbsp; \n</div>",
"<div style=\"white-space:nowrap\">foo&nbsp; &nbsp; <br></div>",
"<div style=\"white-space:nowrap\">foo&nbsp;&nbsp;&nbsp; <br></div>",
],
[true],
{"inserttext":[false,false,"",false,false,""]}],
]
52 changes: 33 additions & 19 deletions editing/other/insertparagraph-with-white-space-style.tentative.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<!doctype html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<meta name="variant" content="?pre">
<meta name="variant" content="?pre-wrap">
<meta name="variant" content="?pre-line">
<meta name="variant" content="?nowrap">
<meta name="variant" content="?white-space=pre&command=insertParagraph">
<meta name="variant" content="?white-space=pre-wrap&command=insertParagraph">
<meta name="variant" content="?white-space=pre-line&command=insertParagraph">
<meta name="variant" content="?white-space=nowrap&command=insertParagraph">
<meta name="variant" content="?white-space=pre&command=insertText">
<meta name="variant" content="?white-space=pre-wrap&command=insertText">
<meta name="variant" content="?white-space=pre-line&command=insertText">
<meta name="variant" content="?white-space=nowrap&command=insertText">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../include/editor-test-utils.js"></script>
Expand All @@ -15,9 +19,19 @@
/**
* The expected behavior is based on Chrome 91.
*/
const style = location.search.substr(1);
const params = new URLSearchParams(location.search);
const style = params.get("white-space");
const isNewLineSignificant = style == "pre" || style == "pre-wrap" || style == "pre-line";
const command = params.get("command");
const editingHost = document.querySelector("div[contenteditable]");
function doIt() {
if (command == "insertParagraph") {
document.execCommand(command);
} else {
// Inserting a linefeed by insertText command should be equivalent of insertParagraph
document.execCommand(command, false, "\n");
}
}
for (const defaultParagraphSeparator of ["div", "p"]) {
document.execCommand("defaultparagraphseparator", false, defaultParagraphSeparator);
for (const display of ["block", "inline", "inline-block"]) {
Expand All @@ -30,7 +44,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`abc[]`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
if (display == "block") {
assert_in_array(
editingHost.innerHTML,
Expand Down Expand Up @@ -64,7 +78,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`[]abc`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
if (display == "block") {
assert_in_array(
editingHost.innerHTML,
Expand Down Expand Up @@ -101,7 +115,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`a[]bc`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
if (display == "block") {
assert_in_array(
editingHost.innerHTML,
Expand Down Expand Up @@ -140,7 +154,7 @@
utils.setupEditingHost(`abc[]`);
editingHost.getBoundingClientRect();
document.execCommand("italic");
document.execCommand("insertparagraph");
doIt();
document.execCommand("inserttext", false, "def");
if (display == "block") {
assert_in_array(
Expand Down Expand Up @@ -184,7 +198,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`<b>abc[]</b>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
document.execCommand("inserttext", false, "def");
if (display == "block") {
assert_in_array(
Expand Down Expand Up @@ -232,7 +246,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`<${paragraph} style="white-space:${style}">abc[]</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
assert_equals(
editingHost.innerHTML,
`<${paragraph} style="white-space:${style}">abc</${paragraph}><${paragraph} style="white-space:${style}"><br></${paragraph}>`,
Expand All @@ -246,7 +260,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`<${paragraph} style="white-space:${style}">[]abc</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
assert_in_array(
editingHost.innerHTML,
[
Expand All @@ -263,7 +277,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`<${paragraph} style="white-space:${style}">a[]bc</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
assert_in_array(
editingHost.innerHTML,
[
Expand All @@ -283,7 +297,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`<${paragraph}>abc[]</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
assert_equals(
editingHost.innerHTML,
`<${paragraph}>abc</${paragraph}><${paragraph}><br></${paragraph}>`,
Expand All @@ -297,7 +311,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`<${paragraph}>[]abc</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
assert_in_array(
editingHost.innerHTML,
[
Expand All @@ -314,7 +328,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`<${paragraph}>a[]bc</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
assert_in_array(
editingHost.innerHTML,
[
Expand All @@ -336,7 +350,7 @@
const styleAttr = `style="display:${display}; white-space:${style}"`;
utils.setupEditingHost(`<${paragraph} ${styleAttr}>abc[]</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
if (display != "block") {
assert_equals(
editingHost.innerHTML,
Expand All @@ -359,7 +373,7 @@
const styleAttr = `style="display:${display}; white-space:${style}"`;
utils.setupEditingHost(`<${paragraph} ${styleAttr}>[]abc</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
if (display != "block") {
assert_in_array(
editingHost.innerHTML,
Expand Down Expand Up @@ -388,7 +402,7 @@
const utils = new EditorTestUtils(editingHost);
utils.setupEditingHost(`<${paragraph} ${styleAttr}>a[]bc</${paragraph}>`);
editingHost.getBoundingClientRect();
document.execCommand("insertparagraph");
doIt();
if (display != "block") {
assert_in_array(
editingHost.innerHTML,
Expand Down

0 comments on commit 5060914

Please sign in to comment.