summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/white-spaces-after-execCommand-forwarddelete.tentative.html
blob: af5c052c563ae19300ef268de5097ee438daa152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Testing normalizing white space sequence after execCommand("forward", false, "")</title>
<script src=../include/implementation.js></script>
<script>var testsJsLibraryOnly = true</script>
<script src="../include/tests.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
"use strict";

setup({explicit_done: true});

function runTests() {
  // README:
  // These tests based on the behavior of Chrome 83.  This test does NOT define
  // nor suggest any standard behavior (actually, some expected results might
  // look odd), but this test must help you to understand how other browsers
  // use different logic to normalize white-space sequence.

  document.body.innerHTML = "<div contenteditable></div>";
  let editor = document.querySelector("div[contenteditable]");
  editor.focus();
  let selection = document.getSelection();

  function toPlaintext(str) {
    return str.replace(/&nbsp;/g, "\u00A0");
  }
  function escape(str) {
    return str.replace(/\u00A0/ig, "&nbsp;");
  }

  // Test simple removing in a text node.
  //  - initialText: Set to data of text node (only &nbsp; entity is handled)
  //  - expectedText: Set to data of the text node after `execCommand("forward")`
  //  - whiteSpaceRange: Set first item to start offset of whitespace sequence,
  //                     set second item to number of white spaces.
  for (const currentTest of [
    { initialText: "a&nbsp;", expectedText: "a", whiteSpaceRange: [1, 1] },
    { initialText: "a&nbsp;&nbsp;", expectedText: "a&nbsp;", whiteSpaceRange: [1, 2] },
    { initialText: "a &nbsp;",      expectedText: "a&nbsp;", whiteSpaceRange: [1, 2] },
    { initialText: "a&nbsp;&nbsp;&nbsp;", expectedText: "a&nbsp;&nbsp;", whiteSpaceRange: [1, 3] },
    { initialText: "a&nbsp; &nbsp;",      expectedText: "a&nbsp;&nbsp;", whiteSpaceRange: [1, 3] },
    { initialText: "a &nbsp;&nbsp;",      expectedText: "a&nbsp;&nbsp;", whiteSpaceRange: [1, 3] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;", expectedText: "a&nbsp; &nbsp;", whiteSpaceRange: [1, 4] },
    { initialText: "a&nbsp;&nbsp; &nbsp;",      expectedText: "a&nbsp; &nbsp;", whiteSpaceRange: [1, 4] },
    { initialText: "a&nbsp; &nbsp;&nbsp;",      expectedText: "a&nbsp; &nbsp;", whiteSpaceRange: [1, 4] },
    { initialText: "a &nbsp; &nbsp;",           expectedText: "a&nbsp; &nbsp;", whiteSpaceRange: [1, 4] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", expectedText: "a&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp; &nbsp; &nbsp;",           expectedText: "a&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp;&nbsp;&nbsp; &nbsp;",      expectedText: "a&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp;&nbsp; &nbsp;&nbsp;",      expectedText: "a&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp; &nbsp;&nbsp;&nbsp;",      expectedText: "a&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;", whiteSpaceRange: [1, 10] },
    { initialText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;",                     expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;", whiteSpaceRange: [1, 10] },
    { initialText: "a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;",                          expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;", whiteSpaceRange: [1, 10] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;", whiteSpaceRange: [1, 11] },
    { initialText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;",                          expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;", whiteSpaceRange: [1, 11] },
    { initialText: "a&nbsp;b", expectedText: "ab", whiteSpaceRange: [1, 1] },
    { initialText: "a b",      expectedText: "ab", whiteSpaceRange: [1, 1] },
    { initialText: "a&nbsp;&nbsp;b", expectedText: "a b", whiteSpaceRange: [1, 2] },
    { initialText: "a&nbsp; b",      expectedText: "a b", whiteSpaceRange: [1, 2] },
    { initialText: "a &nbsp;b",      expectedText: "a b", whiteSpaceRange: [1, 2] },
    { initialText: "a&nbsp;&nbsp;&nbsp;b", expectedText: "a&nbsp; b", whiteSpaceRange: [1, 3] },
    { initialText: "a&nbsp; &nbsp;b",      expectedText: "a&nbsp; b", whiteSpaceRange: [1, 3] },
    { initialText: "a &nbsp; b",           expectedText: "a&nbsp; b", whiteSpaceRange: [1, 3] },
    { initialText: "a &nbsp;&nbsp;b",      expectedText: "a&nbsp; b", whiteSpaceRange: [1, 3] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: "a&nbsp; &nbsp;b", whiteSpaceRange: [1, 4] },
    { initialText: "a&nbsp; &nbsp; b",           expectedText: "a&nbsp; &nbsp;b", whiteSpaceRange: [1, 4] },
    { initialText: "a &nbsp; &nbsp;b",           expectedText: "a&nbsp; &nbsp;b", whiteSpaceRange: [1, 4] },
    { initialText: "a&nbsp;&nbsp; &nbsp;b",      expectedText: "a&nbsp; &nbsp;b", whiteSpaceRange: [1, 4] },
    { initialText: "a&nbsp; &nbsp;&nbsp;b",      expectedText: "a&nbsp; &nbsp;b", whiteSpaceRange: [1, 4] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: "a&nbsp; &nbsp; b", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp; &nbsp; &nbsp;b",           expectedText: "a&nbsp; &nbsp; b", whiteSpaceRange: [1, 5] },
    { initialText: "a &nbsp; &nbsp; b",                expectedText: "a&nbsp; &nbsp; b", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp; b",      expectedText: "a&nbsp; &nbsp; b", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp;&nbsp;&nbsp; &nbsp;b",      expectedText: "a&nbsp; &nbsp; b", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp;&nbsp; &nbsp;&nbsp;b",      expectedText: "a&nbsp; &nbsp; b", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp; &nbsp;&nbsp;&nbsp;b",      expectedText: "a&nbsp; &nbsp; b", whiteSpaceRange: [1, 5] },
    { initialText: "a &nbsp;&nbsp;&nbsp;&nbsp;b",      expectedText: "a&nbsp; &nbsp; b", whiteSpaceRange: [1, 5] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b", whiteSpaceRange: [1, 10] },
    { initialText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b",                          expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b", whiteSpaceRange: [1, 10] },
    { initialText: "a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b",                          expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b", whiteSpaceRange: [1, 10] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b", whiteSpaceRange: [1, 11] },
    { initialText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b",                          expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b", whiteSpaceRange: [1, 11] },
    { initialText: "a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b",                               expectedText: "a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b", whiteSpaceRange: [1, 11] },
    { initialText: "&nbsp;b", expectedText: "b", whiteSpaceRange: [0, 1] },
    { initialText: "&nbsp;&nbsp;b", expectedText: "&nbsp;b", whiteSpaceRange: [0, 2] },
    { initialText: "&nbsp; b",      expectedText: "&nbsp;b", whiteSpaceRange: [0, 2] },
    { initialText: "&nbsp;&nbsp;&nbsp;b", expectedText: "&nbsp; b", whiteSpaceRange: [0, 3] },
    { initialText: "&nbsp; &nbsp;b",      expectedText: "&nbsp; b", whiteSpaceRange: [0, 3] },
    { initialText: "&nbsp;&nbsp; b",      expectedText: "&nbsp; b", whiteSpaceRange: [0, 3] },
    { initialText: "&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: "&nbsp; &nbsp;b", whiteSpaceRange: [0, 4] },
    { initialText: "&nbsp; &nbsp; b",           expectedText: "&nbsp; &nbsp;b", whiteSpaceRange: [0, 4] },
    { initialText: "&nbsp;&nbsp;&nbsp; b",      expectedText: "&nbsp; &nbsp;b", whiteSpaceRange: [0, 4] },
    { initialText: "&nbsp;&nbsp; &nbsp;b",      expectedText: "&nbsp; &nbsp;b", whiteSpaceRange: [0, 4] },
    { initialText: "&nbsp; &nbsp;&nbsp;b",      expectedText: "&nbsp; &nbsp;b", whiteSpaceRange: [0, 4] },
    { initialText: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: "&nbsp; &nbsp; b", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp; &nbsp; &nbsp;b",           expectedText: "&nbsp; &nbsp; b", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp;&nbsp;&nbsp; &nbsp;b",      expectedText: "&nbsp; &nbsp; b", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp;&nbsp; &nbsp;&nbsp;b",      expectedText: "&nbsp; &nbsp; b", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp; &nbsp;&nbsp;&nbsp;b",      expectedText: "&nbsp; &nbsp; b", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b", whiteSpaceRange: [0, 10] },
    { initialText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b",                          expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b", whiteSpaceRange: [0, 10] },
    { initialText: "&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b",                     expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b", whiteSpaceRange: [0, 10] },
    { initialText: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b", whiteSpaceRange: [0, 11] },
    { initialText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b",                          expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b", whiteSpaceRange: [0, 11] },
    { initialText: "&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b",                          expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b", whiteSpaceRange: [0, 11] },
    { initialText: "&nbsp;", expectedText: "", whiteSpaceRange: [0, 1] },
    { initialText: "&nbsp;&nbsp;", expectedText: "&nbsp;", whiteSpaceRange: [0, 2] },
    { initialText: "&nbsp;&nbsp;&nbsp;", expectedText: "&nbsp;&nbsp;", whiteSpaceRange: [0, 3] },
    { initialText: "&nbsp; &nbsp;",      expectedText: "&nbsp;&nbsp;", whiteSpaceRange: [0, 3] },
    { initialText: "&nbsp;&nbsp;&nbsp;&nbsp;", expectedText: "&nbsp; &nbsp;", whiteSpaceRange: [0, 4] },
    { initialText: "&nbsp;&nbsp; &nbsp;",      expectedText: "&nbsp; &nbsp;", whiteSpaceRange: [0, 4] },
    { initialText: "&nbsp; &nbsp;&nbsp;",      expectedText: "&nbsp; &nbsp;", whiteSpaceRange: [0, 4] },
    { initialText: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", expectedText: "&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp; &nbsp; &nbsp;",           expectedText: "&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp;&nbsp;&nbsp; &nbsp;",      expectedText: "&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp;&nbsp; &nbsp;&nbsp;",      expectedText: "&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp; &nbsp;&nbsp;&nbsp;",      expectedText: "&nbsp; &nbsp;&nbsp;", whiteSpaceRange: [0, 5] },
    { initialText: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;", whiteSpaceRange: [0, 10] },
    { initialText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;",                     expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;", whiteSpaceRange: [0, 10] },
    { initialText: "&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;",                     expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;", whiteSpaceRange: [0, 10] },
    { initialText: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;", whiteSpaceRange: [0, 11] },
    { initialText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;",                          expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;", whiteSpaceRange: [0, 11] },
    { initialText: "&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;",                     expectedText: "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;", whiteSpaceRange: [0, 11] },
  ]) {
    for (let i = currentTest.whiteSpaceRange[0]; i < currentTest.whiteSpaceRange[0] + currentTest.whiteSpaceRange[1]; i++) {
      currentTest.getInitialText = function (aCaretPos) {
        return escape(`${toPlaintext(this.initialText).slice(0, aCaretPos)}[]${toPlaintext(this.initialText).slice(aCaretPos)}`);
      }
      test(function () {
        editor.innerHTML = "";
        editor.appendChild(document.createTextNode(toPlaintext(currentTest.initialText)));
        selection.collapse(editor.firstChild, i);
        document.execCommand("forwarddelete", false, "");
        if (currentTest.expectedText.length) {
          assert_equals(escape(editor.childNodes.item(0).data), currentTest.expectedText, "Modified text is wrong");
          assert_equals(selection.focusNode, editor.childNodes.item(0), "Selection focus node is wrong");
          assert_equals(selection.focusOffset, i, "Selection focus offset is wrong");
          assert_equals(selection.anchorNode, editor.childNodes.item(0), "Selection anchor node is wrong");
          assert_equals(selection.anchorOffset, i, "Selection anchor offset is wrong");
        } else {
          assert_equals(escape(editor.textContent), "", "Modified text is wrong");
          assert_equals(selection.focusNode, editor, "Selection focus node is wrong");
          assert_equals(selection.focusOffset, 0, "Selection focus offset is wrong");
          assert_equals(selection.anchorNode, editor, "Selection anchor node is wrong");
          assert_equals(selection.anchorOffset, 0, "Selection anchor offset is wrong");
        }
      }, `execCommand("forwarddelete", false, ""): "${currentTest.getInitialText(i)}" (length of whitespace sequence: ${currentTest.whiteSpaceRange[1]})`);
    }
  }

  // Test white space sequence split to multiple text node.
  //  - initialText: Set to data of text nodes.  This must have "|" at least one.
  //                 Then, the text will be split at every "|".
  //                 Same as above test, only &nbsp; is handled at setting.
  //                 "[]" means that caret position.
  //  - expectedText: Set to data of all text nodes as an array.
  //                  Same as above test, only &nbsp; is handled before comparing.
  for (const currentTest of [
    { initialText: "a&nbsp; []&nbsp;|&nbsp; &nbsp;b", expectedText: ["a&nbsp; []", "&nbsp; &nbsp;b"] },
    { initialText: "a&nbsp; []&nbsp;| &nbsp; b",      expectedText: ["a&nbsp; []", "&nbsp; &nbsp;b"] },
    { initialText: "a&nbsp; &nbsp;[]|&nbsp; &nbsp;b", expectedText: ["a&nbsp; &nbsp;[]", "&nbsp; b"] },
    { initialText: "a&nbsp; &nbsp;[]| &nbsp; b",      expectedText: ["a&nbsp; &nbsp;[]", "&nbsp; b"] },
    { initialText: "a&nbsp; &nbsp;|[]&nbsp; &nbsp;b", expectedText: ["a&nbsp; &nbsp;[]", "&nbsp; b"] },
    { initialText: "a&nbsp; &nbsp;|[] &nbsp; b",      expectedText: ["a&nbsp; &nbsp;[]", "&nbsp; b"] },
    { initialText: "a&nbsp; &nbsp;| []&nbsp; b",      expectedText: ["a&nbsp; &nbsp;", "&nbsp;[] b"] },
    { initialText: "a &nbsp; |[]&nbsp; &nbsp;b",      expectedText: ["a &nbsp; []", "&nbsp; b"] },
    { initialText: "a &nbsp; []|&nbsp; &nbsp;b",      expectedText: ["a &nbsp; []", "&nbsp; b"] },
    { initialText: "a &nbsp;[] |&nbsp; &nbsp;b",      expectedText: ["a &nbsp;[]", "&nbsp; &nbsp;b"] },

    { initialText: "a&nbsp;&nbsp;[]&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: ["a&nbsp; []&nbsp;", "&nbsp;&nbsp;&nbsp;&nbsp;b"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;[]&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: ["a&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp; b"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;[]|&nbsp;&nbsp;&nbsp;&nbsp;b", expectedText: ["a&nbsp;&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp;b"] },
    { initialText: "a&nbsp;[]b&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;c",       expectedText: ["a&nbsp;[] &nbsp;", "&nbsp;&nbsp;&nbsp;&nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;[]b&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp; []&nbsp;&nbsp;", "&nbsp;&nbsp;&nbsp;&nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;[]b|&nbsp;&nbsp;&nbsp;&nbsp;c",       expectedText: ["a&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp; c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;[]|b&nbsp;&nbsp;&nbsp;&nbsp;c",       expectedText: ["a&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp; c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;|[]b&nbsp;&nbsp;&nbsp;&nbsp;c",       expectedText: ["a&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp; c"] },
    { initialText: "a&nbsp;&nbsp;[]&nbsp;|b&nbsp;&nbsp;&nbsp;&nbsp;c",       expectedText: ["a&nbsp;&nbsp;[]", "b&nbsp;&nbsp;&nbsp;&nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;|&nbsp;[]b&nbsp;&nbsp;&nbsp;c",       expectedText: ["a&nbsp;&nbsp;&nbsp;", "&nbsp;[] &nbsp; c"] },

    { initialText: "a&nbsp;&nbsp;&nbsp;|&nbsp;|[]&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;", "&nbsp;[]", "&nbsp; &nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;| |[]&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;", " []", "&nbsp; &nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;| []|&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;", " []", "&nbsp; &nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;|[] |&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp; c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;[]| |&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;[]&nbsp;| |&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;[]", "&nbsp;", "&nbsp;&nbsp;&nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;[]&nbsp;&nbsp;|&nbsp;|&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp; &nbsp;[]&nbsp;", "&nbsp;", "&nbsp;&nbsp;&nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;[]&nbsp;&nbsp;| |&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp; &nbsp;[]&nbsp;", " ", "&nbsp;&nbsp;&nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;[]&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;&nbsp;", "", "&nbsp;[] &nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;||[]&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;|[]|&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;&nbsp;[]||&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp;c"] },
    { initialText: "a&nbsp;&nbsp;&nbsp;[]&nbsp;||&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp;&nbsp;&nbsp;[]", "&nbsp; &nbsp; c"] },
    { initialText: "a&nbsp;&nbsp;[]&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;&nbsp;c", expectedText: ["a&nbsp; []&nbsp;", "", "&nbsp;&nbsp;&nbsp;&nbsp;c"] },
  ]) {
    test(function () {
      editor.innerHTML = "";
      let caret = { container: null, offset: -1 };
      for (let text of toPlaintext(currentTest.initialText).split("|")) {
        let caretOffset = text.indexOf("[]");
        if (caretOffset >= 0) {
          text = text.slice(0, caretOffset) + text.slice(caretOffset + 2);
        }
        let textNode = document.createTextNode(text);
        editor.appendChild(textNode);
        if (caretOffset >= 0) {
          caret = { container: textNode, offset: caretOffset };
        }
      }
      selection.collapse(caret.container, caret.offset);
      document.execCommand("forwarddelete", false, "");
      let child = editor.firstChild;
      for (let expectedText of currentTest.expectedText) {
        expectedText = toPlaintext(expectedText);
        let caretOffset = expectedText.indexOf("[]");
        if (caretOffset >= 0) {
          expectedText = expectedText.slice(0, caretOffset) + expectedText.slice(caretOffset + 2);
        }
        if (!child || child.nodeName !== "#text") {
          assert_equals("", escape(expectedText), "Expected text node is not there");
          if (caretOffset >= 0) {
            assert_equals(-1, caretOffset, "Selection should be contained in this node");
          }
        } else {
          assert_equals(escape(child.data), escape(expectedText), "Modified text is wrong");
          if (caretOffset >= 0) {
            assert_equals(selection.focusNode, child, "Selection focus node is wrong");
            assert_equals(selection.focusOffset, caretOffset, "Selection focus offset is wrong");
            assert_equals(selection.anchorNode, child, "Selection anchor node is wrong");
            assert_equals(selection.anchorOffset, caretOffset, "Selection anchor offset is wrong");
          }
        }
        child = child.nextSibling;
      }
      if (child && child.nodeName === "#text") {
        assert_equals(escape(child.data), "", "Unexpected text node is there");
      }
    }, `execCommand("forwarddelete", false, ""): "${currentTest.initialText}"`);
  }

  // Test white spaces around inline element boundary
  //  - initialHTML: Set to innerHTML of the <div>  ("[{" and "]}" set selection to the range)
  //  - expectedText: Set to innerHTML of the <div> after `execCommand("delete")`
  for (const currentTest of [
    { initialHTML: "<span>abc[] <span>&nbsp;def</span></span>",      expectedHTML: "<span>abc<span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc[]&nbsp;<span>&nbsp;def</span></span>", expectedHTML: "<span>abc<span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc[]&nbsp;<span> def</span></span>",      expectedHTML: "<span>abc<span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc []<span>&nbsp;def</span></span>",      expectedHTML: "<span>abc <span>def</span></span>" },
    { initialHTML: "<span>abc&nbsp;[]<span>&nbsp;def</span></span>", expectedHTML: "<span>abc&nbsp;<span>def</span></span>" },
    { initialHTML: "<span>abc&nbsp;[]<span> def</span></span>",      expectedHTML: "<span>abc&nbsp;<span>def</span></span>" },
    { initialHTML: "<span>abc[]&nbsp;<span>&nbsp; def</span></span>", expectedHTML: "<span>abc<span>&nbsp; def</span></span>" },
    { initialHTML: "<span>abc[]&nbsp;<span> &nbsp;def</span></span>", expectedHTML: "<span>abc<span>&nbsp; def</span></span>" },
    { initialHTML: "<span>abc[]&nbsp; <span>&nbsp;&nbsp;def</span></span>", expectedHTML: "<span>abc&nbsp;<span>&nbsp;&nbsp;def</span></span>" },
    { initialHTML: "<span>abc[]&nbsp; <span>&nbsp; def</span></span>", expectedHTML: "<span>abc&nbsp;<span>&nbsp; def</span></span>" },
    { initialHTML: "<span>abc[]&nbsp;&nbsp;<span>&nbsp;&nbsp;def</span></span>", expectedHTML: "<span>abc&nbsp;<span>&nbsp;&nbsp;def</span></span>" },
    { initialHTML: "<span>abc[] &nbsp;<span>&nbsp;&nbsp;def</span></span>",      expectedHTML: "<span>abc&nbsp;<span>&nbsp;&nbsp;def</span></span>" },
    { initialHTML: "<span>abc[] &nbsp;<span> &nbsp;def</span></span>",           expectedHTML: "<span>abc&nbsp;<span> &nbsp;def</span></span>" },
    { initialHTML: "<span>abc[] &nbsp;<span>&nbsp; def</span></span>",           expectedHTML: "<span>abc&nbsp;<span>&nbsp; def</span></span>" },
    { initialHTML: "<span>abc&nbsp; []<span>&nbsp; def</span></span>",      expectedHTML: "<span>abc&nbsp; <span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc&nbsp; <span>[]&nbsp; def</span></span>",      expectedHTML: "<span>abc&nbsp; <span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc&nbsp;&nbsp;[]<span> &nbsp;def</span></span>", expectedHTML: "<span>abc&nbsp;&nbsp;<span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc&nbsp;&nbsp;<span>[] &nbsp;def</span></span>", expectedHTML: "<span>abc&nbsp;&nbsp;<span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc &nbsp;[]<span>&nbsp; def</span></span>",      expectedHTML: "<span>abc &nbsp;<span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc &nbsp;<span>[]&nbsp; def</span></span>",      expectedHTML: "<span>abc &nbsp;<span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc&nbsp; <span>&nbsp;[] def</span></span>",      expectedHTML: "<span>abc&nbsp; <span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc &nbsp;<span>&nbsp;[] def</span></span>",      expectedHTML: "<span>abc &nbsp;<span>&nbsp;def</span></span>" },
    { initialHTML: "<span>abc &nbsp;<span> []&nbsp;def</span></span>",      expectedHTML: "<span>abc &nbsp;<span>&nbsp;def</span></span>" },

    { initialHTML: "<span><span>abc[] </span>&nbsp;def</span>",      expectedHTML: "<span><span>abc</span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc[]&nbsp;</span>&nbsp;def</span>", expectedHTML: "<span><span>abc</span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc[]&nbsp;</span> def</span>",      expectedHTML: "<span><span>abc</span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc []</span>&nbsp;def</span>",      expectedHTML: "<span><span>abc </span>def</span>" },
    { initialHTML: "<span><span>abc&nbsp;[]</span>&nbsp;def</span>", expectedHTML: "<span><span>abc&nbsp;</span>def</span>" },
    { initialHTML: "<span><span>abc&nbsp;[]</span> def</span>",      expectedHTML: "<span><span>abc&nbsp;</span>def</span>" },
    { initialHTML: "<span><span>abc[]&nbsp;</span>&nbsp; def</span>", expectedHTML: "<span><span>abc</span>&nbsp; def</span>" },
    { initialHTML: "<span><span>abc[]&nbsp;</span> &nbsp;def</span>", expectedHTML: "<span><span>abc</span>&nbsp; def</span>" },
    { initialHTML: "<span><span>abc[]&nbsp; </span>&nbsp;&nbsp;def</span>", expectedHTML: "<span><span>abc&nbsp;</span>&nbsp;&nbsp;def</span>" },
    { initialHTML: "<span><span>abc[]&nbsp; </span>&nbsp; def</span>", expectedHTML: "<span><span>abc&nbsp;</span>&nbsp; def</span>" },
    { initialHTML: "<span><span>abc[]&nbsp;&nbsp;</span>&nbsp;&nbsp;def</span>", expectedHTML: "<span><span>abc&nbsp;</span>&nbsp;&nbsp;def</span>" },
    { initialHTML: "<span><span>abc[] &nbsp;</span>&nbsp;&nbsp;def</span>",      expectedHTML: "<span><span>abc&nbsp;</span>&nbsp;&nbsp;def</span>" },
    { initialHTML: "<span><span>abc[] &nbsp;</span> &nbsp;def</span>",           expectedHTML: "<span><span>abc&nbsp;</span> &nbsp;def</span>" },
    { initialHTML: "<span><span>abc[] &nbsp;</span>&nbsp; def</span>",           expectedHTML: "<span><span>abc&nbsp;</span>&nbsp; def</span>" },
    { initialHTML: "<span><span>abc&nbsp; []</span>&nbsp; def</span>",      expectedHTML: "<span><span>abc&nbsp; </span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc&nbsp; </span>[]&nbsp; def</span>",      expectedHTML: "<span><span>abc&nbsp; </span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc&nbsp;&nbsp;[]</span> &nbsp;def</span>", expectedHTML: "<span><span>abc&nbsp;&nbsp;</span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc&nbsp;&nbsp;</span>[] &nbsp;def</span>", expectedHTML: "<span><span>abc&nbsp;&nbsp;</span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc &nbsp;[]</span>&nbsp; def</span>",      expectedHTML: "<span><span>abc &nbsp;</span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc &nbsp;</span>[]&nbsp; def</span>",      expectedHTML: "<span><span>abc &nbsp;</span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc&nbsp; </span>&nbsp;[] def</span>",      expectedHTML: "<span><span>abc&nbsp; </span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc &nbsp;</span>&nbsp;[] def</span>",      expectedHTML: "<span><span>abc &nbsp;</span>&nbsp;def</span>" },
    { initialHTML: "<span><span>abc &nbsp;</span> []&nbsp;def</span>",      expectedHTML: "<span><span>abc &nbsp;</span>&nbsp;def</span>" },

    { initialHTML: "<span>abc[] </span><span>&nbsp;def</span>",      expectedHTML: "<span>abc</span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc[]&nbsp;</span><span>&nbsp;def</span>", expectedHTML: "<span>abc</span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc[]&nbsp;</span><span> def</span>",      expectedHTML: "<span>abc</span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc []</span><span>&nbsp;def</span>",      expectedHTML: "<span>abc </span><span>def</span>" },
    { initialHTML: "<span>abc&nbsp;[]</span><span>&nbsp;def</span>", expectedHTML: "<span>abc&nbsp;</span><span>def</span>" },
    { initialHTML: "<span>abc&nbsp;[]</span><span> def</span>",      expectedHTML: "<span>abc&nbsp;</span><span>def</span>" },
    { initialHTML: "<span>abc[]&nbsp;</span><span>&nbsp; def</span>", expectedHTML: "<span>abc</span><span>&nbsp; def</span>" },
    { initialHTML: "<span>abc[]&nbsp;</span><span> &nbsp;def</span>", expectedHTML: "<span>abc</span><span>&nbsp; def</span>" },
    { initialHTML: "<span>abc[]&nbsp; </span><span>&nbsp;&nbsp;def</span>", expectedHTML: "<span>abc&nbsp;</span><span>&nbsp;&nbsp;def</span>" },
    { initialHTML: "<span>abc[]&nbsp; </span><span>&nbsp; def</span>", expectedHTML: "<span>abc&nbsp;</span><span>&nbsp; def</span>" },
    { initialHTML: "<span>abc[]&nbsp;&nbsp;</span><span>&nbsp;&nbsp;def</span>", expectedHTML: "<span>abc&nbsp;</span><span>&nbsp;&nbsp;def</span>" },
    { initialHTML: "<span>abc[] &nbsp;</span><span>&nbsp;&nbsp;def</span>",      expectedHTML: "<span>abc&nbsp;</span><span>&nbsp;&nbsp;def</span>" },
    { initialHTML: "<span>abc[] &nbsp;</span><span> &nbsp;def</span>",           expectedHTML: "<span>abc&nbsp;</span><span> &nbsp;def</span>" },
    { initialHTML: "<span>abc[] &nbsp;</span><span>&nbsp; def</span>",           expectedHTML: "<span>abc&nbsp;</span><span>&nbsp; def</span>" },
    { initialHTML: "<span>abc&nbsp; []</span><span>&nbsp; def</span>",      expectedHTML: "<span>abc&nbsp; </span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc&nbsp; </span><span>[]&nbsp; def</span>",      expectedHTML: "<span>abc&nbsp; </span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc&nbsp;&nbsp;[]</span><span> &nbsp;def</span>", expectedHTML: "<span>abc&nbsp;&nbsp;</span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc&nbsp;&nbsp;</span><span>[] &nbsp;def</span>", expectedHTML: "<span>abc&nbsp;&nbsp;</span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc &nbsp;[]</span><span>&nbsp; def</span>",      expectedHTML: "<span>abc &nbsp;</span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc &nbsp;</span><span>[]&nbsp; def</span>",      expectedHTML: "<span>abc &nbsp;</span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc&nbsp; </span><span>&nbsp;[] def</span>",      expectedHTML: "<span>abc&nbsp; </span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc &nbsp;</span><span>&nbsp;[] def</span>",      expectedHTML: "<span>abc &nbsp;</span><span>&nbsp;def</span>" },
    { initialHTML: "<span>abc &nbsp;</span><span> []&nbsp;def</span>",      expectedHTML: "<span>abc &nbsp;</span><span>&nbsp;def</span>" },

    { initialHTML: "a[]<span style=white-space:pre;>b   </span>c", expectedHTML: "a<span style=\"white-space:pre;\">   </span>c" },
    { initialHTML: "a<span style=white-space:pre;>b[]   </span>c", expectedHTML: "a<span style=\"white-space:pre;\">b  </span>c" },
    { initialHTML: "a<span style=white-space:pre;>b []  </span>c", expectedHTML: "a<span style=\"white-space:pre;\">b  </span>c" },
    { initialHTML: "a<span style=white-space:pre;>b  [] </span>c", expectedHTML: "a<span style=\"white-space:pre;\">b  </span>c" },
    { initialHTML: "a<span style=white-space:pre;>b   []</span>c", expectedHTML: "a<span style=\"white-space:pre;\">b   </span>" },
    { initialHTML: "a<span style=white-space:pre;>b  [] </span>", expectedHTML: "a<span style=\"white-space:pre;\">b  </span>" },
    { initialHTML: "a[]<span style=white-space:pre;> </span>b", expectedHTML: "ab" },
    { initialHTML: "a&nbsp;&nbsp;&nbsp;[]<span style=white-space:pre;>   </span>", expectedHTML: "a&nbsp;&nbsp;&nbsp;<span style=\"white-space:pre;\">  </span>" },
    { initialHTML: "a&nbsp;&nbsp;[]&nbsp;<span style=white-space:pre;>   </span>", expectedHTML: "a&nbsp;&nbsp;<span style=\"white-space:pre;\">   </span>" },
    { initialHTML: "a&nbsp;[]&nbsp;&nbsp;<span style=white-space:pre;>   </span>", expectedHTML: "a&nbsp;&nbsp;<span style=\"white-space:pre;\">   </span>" },
    { initialHTML: "a&nbsp;[]&nbsp;&nbsp;<span style=white-space:pre;>b  </span>", expectedHTML: "a&nbsp;&nbsp;<span style=\"white-space:pre;\">b  </span>" },
    { initialHTML: "a&nbsp;&nbsp;&nbsp;[]&nbsp;<span style=white-space:pre;>   </span>", expectedHTML: "a&nbsp;&nbsp;&nbsp;<span style=\"white-space:pre;\">   </span>" },
    { initialHTML: "a&nbsp;&nbsp;[]&nbsp;&nbsp;<span style=white-space:pre;>   </span>", expectedHTML: "a&nbsp; &nbsp;<span style=\"white-space:pre;\">   </span>" },
    { initialHTML: "a&nbsp;&nbsp;[]&nbsp;&nbsp;<span style=white-space:pre;>b  </span>", expectedHTML: "a&nbsp; &nbsp;<span style=\"white-space:pre;\">b  </span>" },
    { initialHTML: "<span style=white-space:pre;> []  </span>&nbsp;&nbsp;&nbsp;a", expectedHTML: "<span style=\"white-space:pre;\">  </span>&nbsp;&nbsp;&nbsp;a" },
    { initialHTML: "<span style=white-space:pre;>  [] </span>&nbsp;&nbsp;&nbsp;a", expectedHTML: "<span style=\"white-space:pre;\">  </span>&nbsp; &nbsp;a" },
    { initialHTML: "<span style=white-space:pre;>   []</span>&nbsp;&nbsp;&nbsp;&nbsp;a", expectedHTML: "<span style=\"white-space:pre;\">   </span>&nbsp; &nbsp;a" },
    { initialHTML: "<span style=white-space:pre;>   </span>[]&nbsp;&nbsp;&nbsp;&nbsp;a", expectedHTML: "<span style=\"white-space:pre;\">   </span>&nbsp; &nbsp;a" },
  ]) {
    test(function () {
      let points = setupDiv(editor, currentTest.initialHTML);
      selection.setBaseAndExtent(points[0], points[1], points[2], points[3]);
      document.execCommand("forwarddelete", false, "");
      assert_equals(editor.innerHTML, currentTest.expectedHTML);
    }, `execCommand("forwarddelete", false, ""): "${currentTest.initialHTML}"`);
  }

  done();
}

window.addEventListener("load", runTests, {once: true});
</script>
</body>
</html>