Skip to content

Commit 5060914

Browse files
masayuki-nakanomoz-wptsync-bot
authored andcommitted
part 8: Update WPT result and add new tests to insert mulitple white-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
1 parent cc0f610 commit 5060914

File tree

2 files changed

+97
-19
lines changed

2 files changed

+97
-19
lines changed

editing/data/inserttext.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,4 +1279,68 @@ var browserTests = [
12791279
"<div contenteditable=\"false\"><span contenteditable=\"\">abcd<br></span></div>"],
12801280
[true],
12811281
{"inserttext":[false,false,"",false,false,""]}],
1282+
["<div style=white-space:pre>foo[]bar</div>",
1283+
[["inserttext"," "]],
1284+
"<div style=\"white-space:pre\">foo bar</div>",
1285+
[true],
1286+
{"inserttext":[false,false,"",false,false,""]}],
1287+
["<div style=white-space:pre>foo[]</div>",
1288+
[["inserttext"," "]],
1289+
"<div style=\"white-space:pre\">foo </div>",
1290+
[true],
1291+
{"inserttext":[false,false,"",false,false,""]}],
1292+
["<div style=white-space:pre-wrap>foo[]bar</div>",
1293+
[["inserttext"," "]],
1294+
"<div style=\"white-space:pre-wrap\">foo bar</div>",
1295+
[true],
1296+
{"inserttext":[false,false,"",false,false,""]}],
1297+
["<div style=white-space:pre-wrap>foo[]</div>",
1298+
[["inserttext"," "]],
1299+
"<div style=\"white-space:pre-wrap\">foo </div>",
1300+
[true],
1301+
{"inserttext":[false,false,"",false,false,""]}],
1302+
// FYI: The white-space sequence different does not matter here. It's tested
1303+
// in white-spaces-after-execCommand-inserttext.tentative.html.
1304+
["<div style=white-space:pre-line>foo[]bar</div>",
1305+
[["inserttext"," "]],
1306+
[
1307+
"<div style=\"white-space:pre-line\">foo &nbsp; &nbsp;bar</div>",
1308+
"<div style=\"white-space:pre-line\">foo&nbsp; &nbsp; bar</div>",
1309+
"<div style=\"white-space:pre-line\">foo&nbsp;&nbsp;&nbsp; bar</div>",
1310+
],
1311+
[true],
1312+
{"inserttext":[false,false,"",false,false,""]}],
1313+
["<div style=white-space:pre-line>foo[]</div>",
1314+
[["inserttext"," "]],
1315+
[
1316+
"<div style=\"white-space:pre-line\">foo &nbsp; &nbsp;</div>",
1317+
"<div style=\"white-space:pre-line\">foo&nbsp; &nbsp;&nbsp;</div>",
1318+
"<div style=\"white-space:pre-line\">foo&nbsp; &nbsp; \n</div>",
1319+
"<div style=\"white-space:pre-line\">foo&nbsp;&nbsp;&nbsp; \n</div>",
1320+
"<div style=\"white-space:pre-line\">foo&nbsp; &nbsp; <br></div>",
1321+
"<div style=\"white-space:pre-line\">foo&nbsp;&nbsp;&nbsp; <br></div>",
1322+
],
1323+
[true],
1324+
{"inserttext":[false,false,"",false,false,""]}],
1325+
["<div style=white-space:nowrap>foo[]bar</div>",
1326+
[["inserttext"," "]],
1327+
[
1328+
"<div style=\"white-space:nowrap\">foo &nbsp; &nbsp;bar</div>",
1329+
"<div style=\"white-space:nowrap\">foo&nbsp; &nbsp; bar</div>",
1330+
"<div style=\"white-space:nowrap\">foo&nbsp;&nbsp;&nbsp; bar</div>",
1331+
],
1332+
[true],
1333+
{"inserttext":[false,false,"",false,false,""]}],
1334+
["<div style=white-space:nowrap>foo[]</div>",
1335+
[["inserttext"," "]],
1336+
[
1337+
"<div style=\"white-space:nowrap\">foo &nbsp; &nbsp;</div>",
1338+
"<div style=\"white-space:nowrap\">foo&nbsp; &nbsp;&nbsp;</div>",
1339+
"<div style=\"white-space:nowrap\">foo&nbsp; &nbsp; \n</div>",
1340+
"<div style=\"white-space:nowrap\">foo&nbsp;&nbsp;&nbsp; \n</div>",
1341+
"<div style=\"white-space:nowrap\">foo&nbsp; &nbsp; <br></div>",
1342+
"<div style=\"white-space:nowrap\">foo&nbsp;&nbsp;&nbsp; <br></div>",
1343+
],
1344+
[true],
1345+
{"inserttext":[false,false,"",false,false,""]}],
12821346
]

editing/other/insertparagraph-with-white-space-style.tentative.html

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<!doctype html>
22
<meta charset=utf-8>
33
<meta name="timeout" content="long">
4-
<meta name="variant" content="?pre">
5-
<meta name="variant" content="?pre-wrap">
6-
<meta name="variant" content="?pre-line">
7-
<meta name="variant" content="?nowrap">
4+
<meta name="variant" content="?white-space=pre&command=insertParagraph">
5+
<meta name="variant" content="?white-space=pre-wrap&command=insertParagraph">
6+
<meta name="variant" content="?white-space=pre-line&command=insertParagraph">
7+
<meta name="variant" content="?white-space=nowrap&command=insertParagraph">
8+
<meta name="variant" content="?white-space=pre&command=insertText">
9+
<meta name="variant" content="?white-space=pre-wrap&command=insertText">
10+
<meta name="variant" content="?white-space=pre-line&command=insertText">
11+
<meta name="variant" content="?white-space=nowrap&command=insertText">
812
<script src="/resources/testharness.js"></script>
913
<script src="/resources/testharnessreport.js"></script>
1014
<script src="../include/editor-test-utils.js"></script>
@@ -15,9 +19,19 @@
1519
/**
1620
* The expected behavior is based on Chrome 91.
1721
*/
18-
const style = location.search.substr(1);
22+
const params = new URLSearchParams(location.search);
23+
const style = params.get("white-space");
1924
const isNewLineSignificant = style == "pre" || style == "pre-wrap" || style == "pre-line";
25+
const command = params.get("command");
2026
const editingHost = document.querySelector("div[contenteditable]");
27+
function doIt() {
28+
if (command == "insertParagraph") {
29+
document.execCommand(command);
30+
} else {
31+
// Inserting a linefeed by insertText command should be equivalent of insertParagraph
32+
document.execCommand(command, false, "\n");
33+
}
34+
}
2135
for (const defaultParagraphSeparator of ["div", "p"]) {
2236
document.execCommand("defaultparagraphseparator", false, defaultParagraphSeparator);
2337
for (const display of ["block", "inline", "inline-block"]) {
@@ -30,7 +44,7 @@
3044
const utils = new EditorTestUtils(editingHost);
3145
utils.setupEditingHost(`abc[]`);
3246
editingHost.getBoundingClientRect();
33-
document.execCommand("insertparagraph");
47+
doIt();
3448
if (display == "block") {
3549
assert_in_array(
3650
editingHost.innerHTML,
@@ -64,7 +78,7 @@
6478
const utils = new EditorTestUtils(editingHost);
6579
utils.setupEditingHost(`[]abc`);
6680
editingHost.getBoundingClientRect();
67-
document.execCommand("insertparagraph");
81+
doIt();
6882
if (display == "block") {
6983
assert_in_array(
7084
editingHost.innerHTML,
@@ -101,7 +115,7 @@
101115
const utils = new EditorTestUtils(editingHost);
102116
utils.setupEditingHost(`a[]bc`);
103117
editingHost.getBoundingClientRect();
104-
document.execCommand("insertparagraph");
118+
doIt();
105119
if (display == "block") {
106120
assert_in_array(
107121
editingHost.innerHTML,
@@ -140,7 +154,7 @@
140154
utils.setupEditingHost(`abc[]`);
141155
editingHost.getBoundingClientRect();
142156
document.execCommand("italic");
143-
document.execCommand("insertparagraph");
157+
doIt();
144158
document.execCommand("inserttext", false, "def");
145159
if (display == "block") {
146160
assert_in_array(
@@ -184,7 +198,7 @@
184198
const utils = new EditorTestUtils(editingHost);
185199
utils.setupEditingHost(`<b>abc[]</b>`);
186200
editingHost.getBoundingClientRect();
187-
document.execCommand("insertparagraph");
201+
doIt();
188202
document.execCommand("inserttext", false, "def");
189203
if (display == "block") {
190204
assert_in_array(
@@ -232,7 +246,7 @@
232246
const utils = new EditorTestUtils(editingHost);
233247
utils.setupEditingHost(`<${paragraph} style="white-space:${style}">abc[]</${paragraph}>`);
234248
editingHost.getBoundingClientRect();
235-
document.execCommand("insertparagraph");
249+
doIt();
236250
assert_equals(
237251
editingHost.innerHTML,
238252
`<${paragraph} style="white-space:${style}">abc</${paragraph}><${paragraph} style="white-space:${style}"><br></${paragraph}>`,
@@ -246,7 +260,7 @@
246260
const utils = new EditorTestUtils(editingHost);
247261
utils.setupEditingHost(`<${paragraph} style="white-space:${style}">[]abc</${paragraph}>`);
248262
editingHost.getBoundingClientRect();
249-
document.execCommand("insertparagraph");
263+
doIt();
250264
assert_in_array(
251265
editingHost.innerHTML,
252266
[
@@ -263,7 +277,7 @@
263277
const utils = new EditorTestUtils(editingHost);
264278
utils.setupEditingHost(`<${paragraph} style="white-space:${style}">a[]bc</${paragraph}>`);
265279
editingHost.getBoundingClientRect();
266-
document.execCommand("insertparagraph");
280+
doIt();
267281
assert_in_array(
268282
editingHost.innerHTML,
269283
[
@@ -283,7 +297,7 @@
283297
const utils = new EditorTestUtils(editingHost);
284298
utils.setupEditingHost(`<${paragraph}>abc[]</${paragraph}>`);
285299
editingHost.getBoundingClientRect();
286-
document.execCommand("insertparagraph");
300+
doIt();
287301
assert_equals(
288302
editingHost.innerHTML,
289303
`<${paragraph}>abc</${paragraph}><${paragraph}><br></${paragraph}>`,
@@ -297,7 +311,7 @@
297311
const utils = new EditorTestUtils(editingHost);
298312
utils.setupEditingHost(`<${paragraph}>[]abc</${paragraph}>`);
299313
editingHost.getBoundingClientRect();
300-
document.execCommand("insertparagraph");
314+
doIt();
301315
assert_in_array(
302316
editingHost.innerHTML,
303317
[
@@ -314,7 +328,7 @@
314328
const utils = new EditorTestUtils(editingHost);
315329
utils.setupEditingHost(`<${paragraph}>a[]bc</${paragraph}>`);
316330
editingHost.getBoundingClientRect();
317-
document.execCommand("insertparagraph");
331+
doIt();
318332
assert_in_array(
319333
editingHost.innerHTML,
320334
[
@@ -336,7 +350,7 @@
336350
const styleAttr = `style="display:${display}; white-space:${style}"`;
337351
utils.setupEditingHost(`<${paragraph} ${styleAttr}>abc[]</${paragraph}>`);
338352
editingHost.getBoundingClientRect();
339-
document.execCommand("insertparagraph");
353+
doIt();
340354
if (display != "block") {
341355
assert_equals(
342356
editingHost.innerHTML,
@@ -359,7 +373,7 @@
359373
const styleAttr = `style="display:${display}; white-space:${style}"`;
360374
utils.setupEditingHost(`<${paragraph} ${styleAttr}>[]abc</${paragraph}>`);
361375
editingHost.getBoundingClientRect();
362-
document.execCommand("insertparagraph");
376+
doIt();
363377
if (display != "block") {
364378
assert_in_array(
365379
editingHost.innerHTML,
@@ -388,7 +402,7 @@
388402
const utils = new EditorTestUtils(editingHost);
389403
utils.setupEditingHost(`<${paragraph} ${styleAttr}>a[]bc</${paragraph}>`);
390404
editingHost.getBoundingClientRect();
391-
document.execCommand("insertparagraph");
405+
doIt();
392406
if (display != "block") {
393407
assert_in_array(
394408
editingHost.innerHTML,

0 commit comments

Comments
 (0)