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
|
<!DOCTYPE html>
<html>
<head>
<title>Paragraph boundary getText* functions tests</title>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../text.js"></script>
<script type="application/javascript">
function doTest() {
// First, test the contentEditable.
testTextAtOffset("ce", BOUNDARY_PARAGRAPH,
[[0, 0, kEmbedChar, 0, 1],
[1, 2, kEmbedChar, 1, 2]]);
// Now, test each paragraph.
var ID = getNode("ce").firstElementChild;
testTextAtOffset(ID, BOUNDARY_PARAGRAPH,
[[0, 15, "hello my friend", 0, 15]]);
ID = getNode("ce").lastElementChild;
testTextAtOffset(ID, BOUNDARY_PARAGRAPH,
[[0, 11, "hello again", 0, 11]]);
// Test a paragraph whose line forcefully wraps.
testTextAtOffset("forced_wrap", BOUNDARY_PARAGRAPH,
[[0, 2, "ab", 0, 2]]);
// Test paragraphs with a few line breaks.
testTextAtOffset("forced_br", BOUNDARY_PARAGRAPH,
[[0, 1, "a\n", 0, 2], // a and br treated as a paragraph
[2, 3, "b\n", 2, 4], // b treated as a paragraph, excl 2nd line break
[4, 4, "\n", 4, 5], // second br treated as a separate paragraph
[5, 6, "c", 5, 6]]); // Last paragraph treated as usual
testTextAtOffset("br_at_beginning", BOUNDARY_PARAGRAPH,
[[0, 0, "\n", 0, 1], // br treated as a separate paragraph
[1, 2, "a\n", 1, 3], // a and br treated as a paragraph
[3, 4, "b", 3, 4]]); // b treated as last paragraph
// Test a paragraph with an embedded link.
testTextAtOffset("pWithLink", BOUNDARY_PARAGRAPH,
[[0, 3, "a" + kEmbedChar + "d", 0, 3]]);
testTextAtOffset("link", BOUNDARY_PARAGRAPH,
[[0, 2, "bc", 0, 2]]);
// Paragraph with link that contains a line break.
testTextAtOffset("pWithLinkWithBr", BOUNDARY_PARAGRAPH,
[[0, 0, "a" + kEmbedChar, 0, 2],
[1, 1, "a" + kEmbedChar + "d", 0, 3],
[2, 3, kEmbedChar + "d", 1, 3]]);
// Test a list and list item
testTextAtOffset("ul", BOUNDARY_PARAGRAPH,
[[0, 0, kEmbedChar, 0, 1],
[1, 2, kEmbedChar, 1, 2]]);
testTextAtOffset("li1", BOUNDARY_PARAGRAPH,
[[0, 3, "• a", 0, 3]]);
testTextAtOffset("li2", BOUNDARY_PARAGRAPH,
[[0, 3, "• a", 0, 3]]);
// Test a list item containing multiple text leaf nodes.
testTextAtOffset("liMultiLeaf", BOUNDARY_PARAGRAPH,
[[0, 4, "• ab", 0, 4]]);
// Test line breaks in a textarea.
testTextAtOffset("textarea", BOUNDARY_PARAGRAPH,
[[0, 1, "a\n", 0, 2],
[2, 3, "b\n", 2, 4],
[4, 4, "\n", 4, 5],
[5, 6, "c", 5, 6]]);
// Test that a textarea has a blank paragraph at the end if it contains
// a line break as its last character.
testTextAtOffset("textarea_with_trailing_br", BOUNDARY_PARAGRAPH,
[[0, 15, "This is a test.\n", 0, 16],
[16, 16, "", 16, 16]]);
// Paragraph with a presentational line break.
testTextAtOffset("presentational_br", BOUNDARY_PARAGRAPH,
[[0, 3, "a b", 0, 3]]);
// Two paragraphs in a div, non-editable case.
testTextAtOffset("two_paragraphs", BOUNDARY_PARAGRAPH,
[[0, 0, kEmbedChar, 0, 1],
[1, 2, kEmbedChar, 1, 2]]);
// Div containing a paragraph containing a link
testTextAtOffset("divWithParaWithLink", BOUNDARY_PARAGRAPH,
[[0, 0, kEmbedChar, 0, 1],
[1, 2, "b", 1, 2]]);
// Two text nodes and a br
testTextAtOffset("twoTextNodesAndBr", BOUNDARY_PARAGRAPH,
[[0, 2, "ab\n", 0, 3],
[3, 3, "", 3, 3]]);
// Link followed by a paragraph.
testTextAtOffset("linkThenPara", BOUNDARY_PARAGRAPH,
[[0, 0, kEmbedChar, 0, 1],
[1, 2, kEmbedChar, 1, 2]]);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<a target="_blank"
title="getTextAtOffset for paragraph boundaries"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=1520779">
Bug 1520779
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<div id="ce" contenteditable="true">
<p>hello my friend</p>
<p>hello again</p>
</div>
<p id="forced_wrap" style="width: 1px; word-break: break-all;">ab</p>
<p id="forced_br">a<br>b<br><br>c</p>
<p id="br_at_beginning"><br>a<br>b</p>
<p id="pWithLink">a<a id="link" href="https://example.com/">bc</a>d</p>
<p id="pWithLinkWithBr">a<a href="#">b<br>c</a>d</p>
<ul id="ul"><li id="li1">a</li><li>b</li></ul>
<style>#li2::marker { content:'\2022\0020'; }</style>
<ul id="ul"><li id="li2">a</li><li>b</li></ul>
<ul><li id="liMultiLeaf">a<span>b</span></li></ul>
<textarea id="textarea">a
b
c</textarea> <!-- This must be outdented for a correct test case -->
<textarea id="textarea_with_trailing_br">This is a test.
</textarea> <!-- This must be outdented for a correct test case -->
<p id="presentational_br" style="white-space: pre-wrap;">a<span> <br role="presentation"></span>b</p>
<div id="two_paragraphs"><p>a</p><p>b</p></div>
<div id ="divWithParaWithLink"><p><a href="#">a</a></p>b</div>
<p id="twoTextNodesAndBr">a<span>b</span><br></p>
<div id="linkThenPara"><a href="#">a</a><p>b</p></div>
</body>
</html>
|