summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_text_wholeText.html
blob: 31fa0f07667864bbf7511cbffceb0991524de5cd (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=421765
-->
<head>
  <title>Text.wholeText tests</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=421765">Mozilla Bug 421765</a>
<p id="display"></p>
<div id="content" style="display: none"></div>

<iframe id="xmlDocument" src="wholeTexty-helper.xml"></iframe>

<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 421765 **/

SimpleTest.waitForExplicitFinish();

var xmlDoc;

function text(t) { return document.createTextNode(t); }
function element() { return document.createElement("div"); }
function cdata(t)
{
  xmlDoc = $("xmlDocument").contentDocument;
  // document.createCDATASection isn't implemented; clone for the win
  var node = xmlDoc.documentElement.firstChild.cloneNode(false);
  is(node.nodeType, Node.CDATA_SECTION_NODE,
     "er, why isn't this a CDATA section node?");
  node.data = t;
  return node;
}


function firstTests()
{
  var outer = element();
  var first = text("first");
  var second = element();
  second.appendChild(text("element contents"));
  outer.appendChild(first);
  outer.appendChild(second);

  is(first.wholeText, "first", "wrong wholeText for first");

  var insertedText = text("-continued");
  outer.insertBefore(insertedText, second);

  is(first.wholeText, "first-continued",
     "wrong wholeText for first after insertedText insertion");
  is(insertedText.wholeText, "first-continued",
     "wrong wholeText for insertedText after insertedText insertion");

  var cdataNode = cdata("zero-")
  outer.insertBefore(cdataNode, first);

  is(first.wholeText, "zero-first-continued",
     "wrong wholeText for first after cdataNode insertion");
  is(cdataNode.wholeText, "zero-first-continued",
     "wrong wholeText for cdataNode after cdataNode insertion");
  is(insertedText.wholeText, "zero-first-continued",
     "wrong wholeText for insertedText after cdataNode insertion");

  outer.insertBefore(element(), first);

  is(first.wholeText, "first-continued",
     "wrong wholeText for first after element insertion");
  is(cdataNode.wholeText, "zero-",
     "wrong wholeText for cdataNode after element insertion");
  is(insertedText.wholeText, "first-continued",
     "wrong wholeText for insertedText after element insertion");

  var cdataNode2 = cdata("-interrupted");
  outer.insertBefore(cdataNode2, insertedText);

  is(first.wholeText, "first-interrupted-continued",
     "wrong wholeText for first after cdataNode2 insertion");
  is(cdataNode2.wholeText, "first-interrupted-continued",
     "wrong wholeText for cdataNode2 after cdataNode2 insertion");
  is(insertedText.wholeText, "first-interrupted-continued",
     "wrong wholeText for insertedText after cdataNode2 insertion");
}

function middleTests()
{
  var outer = element();
  var first = element();
  var last = element();
  var middle = text("middle");
  first.appendChild(text("first element contents"));
  last.appendChild(text("last element contents"));
  outer.appendChild(first);
  outer.appendChild(middle);
  outer.appendChild(last);

  is(middle.wholeText, "middle", "wrong wholeText for middle");

  var beforeMiddle = text("before-");
  outer.insertBefore(beforeMiddle, middle);

  is(middle.wholeText, "before-middle",
     "wrong wholeText for middle after beforeMiddle insertion");
  is(beforeMiddle.wholeText, "before-middle",
     "wrong wholeText for beforeMiddle after beforeMiddle insertion");

  var midElement = element();
  midElement.appendChild(text("middle element"));
  outer.insertBefore(midElement, middle);

  is(middle.wholeText, "middle",
     "wrong wholeText for middle after midElement insertion");
  is(beforeMiddle.wholeText, "before-",
     "wrong wholeText for beforeMiddle after midElement insertion");

  var cdataNode = cdata("after");
  outer.insertBefore(cdataNode, midElement);

  is(cdataNode.wholeText, "before-after",
     "wrong wholeText for cdataNode after cdataNode insertion");
  is(beforeMiddle.wholeText, "before-after",
     "wrong wholeText for beforeMiddle after cdataNode insertion");
  is(middle.wholeText, "middle",
     "wrong wholeText for middle after cdataNode insertion");

  var cdataNode2 = cdata("before-");
  outer.insertBefore(cdataNode2, middle);

  is(cdataNode.wholeText, "before-after",
     "wrong wholeText for cdataNode after cdataNode2 insertion");
  is(beforeMiddle.wholeText, "before-after",
     "wrong wholeText for beforeMiddle after cdataNode2 insertion");
  is(cdataNode2.wholeText, "before-middle",
     "wrong wholeText for middle after cdataNode2 insertion");
  is(middle.wholeText, "before-middle",
     "wrong wholeText for middle after cdataNode2 insertion");
}

function lastTests()
{
  var outer = element();
  var first = element();
  var second = text("second");
  first.appendChild(text("element contents"));
  outer.appendChild(first);
  outer.appendChild(second);

  is(second.wholeText, "second", "wrong wholeText for second");

  var insertedText = text("before-");
  outer.insertBefore(insertedText, second);

  is(second.wholeText, "before-second",
     "wrong wholeText for second after insertedText insertion");
  is(insertedText.wholeText, "before-second",
     "wrong wholeText for insertedText after insertedText insertion");

  var cdataNode = cdata("zero-")
  outer.insertBefore(cdataNode, insertedText);

  is(cdataNode.wholeText, "zero-before-second",
     "wrong wholeText for cdataNode after cdataNode insertion");
  is(second.wholeText, "zero-before-second",
     "wrong wholeText for second after cdataNode insertion");
  is(insertedText.wholeText, "zero-before-second",
     "wrong wholeText for insertedText after cdataNode insertion");

  outer.insertBefore(element(), second);

  is(second.wholeText, "second",
     "wrong wholeText for second after element insertion");
  is(cdataNode.wholeText, "zero-before-",
     "wrong wholeText for cdataNode after element insertion");
  is(insertedText.wholeText, "zero-before-",
     "wrong wholeText for insertedText after element insertion");

  var cdataNode2 = cdata("interrupted-");
  outer.insertBefore(cdataNode2, insertedText);

  is(second.wholeText, "second",
     "wrong wholeText for second after cdataNode2 insertion");
  is(cdataNode2.wholeText, "zero-interrupted-before-",
     "wrong wholeText for cdataNode2 after cdataNode2 insertion");
  is(insertedText.wholeText, "zero-interrupted-before-",
     "wrong wholeText for insertedText after cdataNode2 insertion");
}

function noParentTests()
{
  var textNode = text("foobar");
  is(textNode.wholeText, textNode.data,
     "orphaned textNode should have wholeText == data");
  is(textNode.wholeText, "foobar",
     "orphaned textNode should have wholeText == 'foobar'");

  var cdataSection = cdata("baz");
  is(cdataSection.wholeText, cdataSection.data,
     "orphaned cdatasection should have wholeText == data");
  is(cdataSection.wholeText, "baz",
     "orphaned cdatasection should have wholeText == data");
}

function tests()
{
  try
  {
    firstTests();
    middleTests();
    lastTests();
    noParentTests();
  }
  catch (e)
  {
    ok(false, "error thrown: " + e);
  }
  finally
  {
    SimpleTest.finish();
  }
}

window.addEventListener("load", tests, false);
</script>
</pre>
</body>
</html>