summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/insert-list-preserving-selection.tentative.html
blob: b7faf4f27ae012f192ad919a20773d59cff2db00 (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
<!doctype html>
<html>
<head>
<meta chareset="utf-8">
<meta name="timeout" content="long">
<meta name="variant" content="?styleWithCSS=false&command=insertOrderedList">
<meta name="variant" content="?styleWithCSS=false&command=insertUnorderedList">
<meta name="variant" content="?styleWithCSS=true&command=insertOrderedList">
<meta name="variant" content="?styleWithCSS=true&command=insertUnorderedList">
<title>Test preserving selection after insert*List</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="../include/editor-test-utils.js"></script>
</head>
<body>
<div contenteditable></div>
<script>
"use strict";

const editor = document.querySelector("div[contenteditable]");
const utils = new EditorTestUtils(editor);
const searchParams = new URLSearchParams(document.location.search);
const styleWithCSS = searchParams.get("styleWithCSS");
const command = searchParams.get("command");
document.execCommand("styleWithCSS", false, styleWithCSS);

// Note that it's not scope of this test how browsers to convert the selected
// content to a list.

// html: Initial HTML which will be set editor.innerHTML, it should contain
//       selection range with a pair of "[" or "{" and "]" or "}".
// expectedSelectedString: After executing "outdent", compared with
//                         getSelection().toString().replace(/[ \n\r\t]+/g, "")
const tests = [
  {
    html: "<div>a[b]c</div>",
    expectedSelectedString: "b",
  },
  {
    html: "<div>a[bc</div><div>de]f</div>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<div>a[bc<br>de]f</div>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ul><li>a[b]c</li></ul>",
    expectedSelectedString: "b",
  },
  {
    html: "<ul><li>a[bc</li><li>de]f</li></ul>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ul><li>a[bc</li><li>de]f</li><li>ghi</li></ul>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ul><li>abc</li><li>d[ef</li><li>gh]i</li></ul>",
    expectedSelectedString: "efgh",
  },
  {
    html: "<ol><li>a[b]c</li></ol>",
    expectedSelectedString: "b",
  },
  {
    html: "<ol><li>a[bc</li><li>de]f</li></ol>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ol><li>a[bc</li><li>de]f</li><li>ghi</li></ol>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ol><li>abc</li><li>d[ef</li><li>gh]i</li></ol>",
    expectedSelectedString: "efgh",
  },
  {
    html: "<ul><li>a[bc</li></ul>" +
          "<ul><li>de]f</li></ul>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ol><li>a[bc</li></ol>" +
          "<ul><li>de]f</li></ul>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ul><li>a[bc</li></ul>" +
          "<ol><li>de]f</li></ol>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<div>a[bc</div>" +
          "<ul><li>de]f</li><li>ghi</li></ul>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ul><li>abc</li><li>d[ef</li></ul>" +
          "<div>gh]i</div>",
    expectedSelectedString: "efgh",
  },
  {
    html: "<div>a[bc</div>" +
          "<ol><li>de]f</li><li>ghi</li></ol>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<ol><li>abc</li><li>d[ef</li></ol>" +
          "<div>gh]i</div>",
    expectedSelectedString: "efgh",
  },
  {
    html: "<table><tr><td>a[b]c</td></tr></table>",
    expectedSelectedString: "b",
  },
  {
    html: "<table><tr><td>a[bc</td><td>de]f</td></tr></table>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<table><tr><td>a[bc</td></tr><tr><td>de]f</td></tr></table>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<div>a[bc</div>" +
          "<table><tr><td>de]f</td></tr></table>",
    expectedSelectedString: "bcde",
  },
  {
    html: "<table><tr><td>a[bc</td></tr></table>" +
          "<div>de]f</div>",
    expectedSelectedString: "bcde",
  },
];

for (const t of tests) {
  test(() => {
    utils.setupEditingHost(t.html);
    document.execCommand(command);
    assert_equals(
      getSelection().toString().replace(/[ \n\r\t]+/g, ""),
      t.expectedSelectedString,
      `Result: ${editor.innerHTML}`
    );
  }, `Preserve selection after ${command} at ${t.html}`);
}

</script>
</body>
</html>