summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/extra-text-nodes.html
blob: 2cd1232d00b8bdcf3a48ba01b3f2cfd05e27f094 (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
<!doctype html>
<meta charset=utf-8>
<title>Editor should not create unnecessary text nodes</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div contenteditable></div>
<script>
var div = document.querySelector("div");
var walker = document.createTreeWalker(div, NodeFilter.SHOW_TEXT);
function testInput(html, callback, desc) {
  test(() => {
    div.innerHTML = html;
    div.focus();
    callback();

    walker.currentNode = walker.root;
    var node;
    while (node = walker.nextNode()) {
      if (node.nextSibling) {
        assert_not_equals(node.nextSibling.nodeType, Node.TEXT_NODE,
                          'text node "' + node.nodeValue + '" is next to "' +
                          node.nextSibling.nodeValue + '"');
      }
    }
  }, desc);
}

[
  ['<img src="#">foo<img src="#">',
   () => {
     getSelection().collapse(div, 1);
     document.execCommand("inserttext", false, "x");
   },
   "Simple insertText"],
  ['<p>editor</p>',
   () => {
     getSelection().collapse(div.firstChild.firstChild, 3);
     document.execCommand("insertlinebreak", false, "");
     document.execCommand("inserttext", false, "x");
   },
   "insertText after insertLineBreak"],
].forEach(([a, b, c]) => testInput(a, b, c));
</script>