summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_insertText_around_text_node_in_plaintext_mode.html
blob: 1acf31945682e8a05fff6fcac41d21c868f0cefe (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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test insertText when caret is around a text node</title>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script>
"use strict";

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  function getHTMLEditor() {
    let editingSession = SpecialPowers.wrap(window).docShell.editingSession;
    if (!editingSession) {
      return null;
    }
    let editor = editingSession.getEditorForWindow(window);
    if (!editor) {
      return null;
    }
    return editor.QueryInterface(SpecialPowers.Ci.nsIHTMLEditor);
  }

  document.designMode = "on";
  document.body.focus();
  await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
  const editor = getHTMLEditor();
  editor.flags |= SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask;

  (function test_collapsed_before_first_text_child() {
    document.body.innerHTML = "bc<br>";
    getSelection().collapse(document.body, 0);
    document.execCommand("insertText", false, "a");
    is(
      document.body.firstChild.data,
      "abc",
      "test_collapsed_before_first_text_child: Text should be inserted into start of the first text child"
    );
  })();

  (function test_collapsed_before_first_text_child() {
    document.body.innerHTML = "bc<br>";
    getSelection().collapse(document.body, 0);
    document.execCommand("insertText", false, "a");
    is(
      document.body.firstChild.data,
      "abc",
      "test_collapsed_before_first_text_child: Text should be inserted into start of the first text child"
    );
  })();

  (function test_collapsed_after_last_text_child() {
    document.body.innerHTML = "ab";
    getSelection().collapse(document.body, 1);
    document.execCommand("insertText", false, "c");
    is(
      document.body.firstChild.data,
      "abc",
      "test_collapsed_after_last_text_child: Text should be inserted into end of the last text child"
    );
  })();

  (function test_collapsed_after_text_child() {
    document.body.innerHTML = "ab<br>";
    getSelection().collapse(document.body, 1);
    document.execCommand("insertText", false, "c");
    is(
      document.body.firstChild.data,
      "abc",
      "test_collapsed_after_text_child: Text should be inserted into end of the previous text child"
    );
  })();

  (function test_collapsed_at_text_child() {
    document.body.innerHTML = "<img>bc";
    getSelection().collapse(document.body, 1);
    document.execCommand("insertText", false, "a");
    is(
      document.body.firstChild.nextSibling.data,
      "abc",
      "test_collapsed_at_text_child: Text should be inserted into start of the text child"
    );
  })();

  document.designMode = "off";
  SimpleTest.finish();
});
</script>
<body></body>
</html>