File: insertParagraph.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (97 lines) | stat: -rw-r--r-- 3,451 bytes parent folder | download | duplicates (13)
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long">
<meta name="variant" content="?white-space=normal">
<meta name="variant" content="?white-space=pre">
<meta name="variant" content="?white-space=pre-line">
<meta name="variant" content="?white-space=pre-wrap">
<title>excCommand("insertParagraph") in plaintext-only</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../include/editor-test-utils.js"></script>
<script>
"use strict";

const searchParams = new URLSearchParams(document.location.search);
const whiteSpace = searchParams.get("white-space");
const useBR = whiteSpace == "normal";

addEventListener("load", () => {
  const editingHost = document.createElement("div");
  editingHost.style.whiteSpace = whiteSpace;
  editingHost.setAttribute("contenteditable", "plaintext-only");
  document.body.appendChild(editingHost);
  editingHost.focus();
  editingHost.getBoundingClientRect();
  const utils = new EditorTestUtils(editingHost);

  /**
   * insertParagraph command in plaintext-only is available only with document.execCommand.
   * It should work as same as contenteditable=true, therefore, this test checks only
   * basic behavior.  Various edge cases should be tested in run/insertparagraph.html.
   *
   * Currently, <br> is used for padding line break in empty paragraph.  This won't appear
   * in `.textContent` of the editing host, but the paragraph itself does not appear in
   * the value too.  Therefore, web apps anyway need to use `.innerHTML` to get the result.
   * So, using <br> should not be a problem for web apps.
   */

  for (const data of [
    {
      initialInnerHTML: "<p>[]AB</p>",
      expected: "<p><br></p><p>AB</p>",
    },
    {
      initialInnerHTML: "<p>A[]B</p>",
      expected: "<p>A</p><p>B</p>",
    },
    {
      initialInnerHTML: "<p>AB[]</p>",
      expected: "<p>AB</p><p><br></p>",
    },
    {
      initialInnerHTML: `<p style="white-space:normal">[]AB</p>`,
      expected: `<p style="white-space:normal"><br></p><p style="white-space:normal">AB</p>`,
    },
    {
      initialInnerHTML: `<p style="white-space:pre">[]AB</p>`,
      expected: `<p style="white-space:pre"><br></p><p style="white-space:pre">AB</p>`,
    },
    {
      initialInnerHTML: `<p style="white-space:pre-line">[]AB</p>`,
      expected: `<p style="white-space:pre-line"><br></p><p style="white-space:pre-line">AB</p>`,
    },
    {
      initialInnerHTML: `<p style="white-space:pre-wrap">[]AB</p>`,
      expected: `<p style="white-space:pre-wrap"><br></p><p style="white-space:pre-wrap">AB</p>`,
    },
    {
      initialInnerHTML: "<ul><li>[]AB</li></ul>",
      expected: "<ul><li><br></li><li>AB</li></ul>",
    },
    {
      initialInnerHTML: "<ul><li>A[]B</li></ul>",
      expected: "<ul><li>A</li><li>B</li></ul>",
    },
    {
      initialInnerHTML: "<ul><li>AB[]</li></ul>",
      expected: "<ul><li>AB</li><li><br></li></ul>",
    },
  ]) {
    test(() => {
      utils.setupEditingHost(data.initialInnerHTML);
      document.execCommand("insertParagraph");
      if (Array.isArray(data.expected)) {
        assert_in_array(editingHost.innerHTML, data.expected);
      } else {
        assert_equals(editingHost.innerHTML, data.expected);
      }
    }, `execCommand("insertParagraph") when ${data.initialInnerHTML}`);
  }
}, {once: true});
</script>
</head>
<body></body>
</html>