4 https://bugzilla.mozilla.org/show_bug.cgi?id=421765
7 <title>Text.wholeText tests
</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
12 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=421765">Mozilla Bug
421765</a>
14 <div id=
"content" style=
"display: none"></div>
16 <iframe id=
"xmlDocument" src=
"wholeTexty-helper.xml"></iframe>
19 <script class=
"testbody" type=
"text/javascript">
21 /** Test for Bug
421765 **/
23 SimpleTest.waitForExplicitFinish();
27 function text(t) { return document.createTextNode(t); }
28 function element() { return document.createElement(
"div"); }
31 xmlDoc = $(
"xmlDocument").contentDocument;
32 // document.createCDATASection isn't implemented; clone for the win
33 var node = xmlDoc.documentElement.firstChild.cloneNode(false);
34 is(node.nodeType, Node.CDATA_SECTION_NODE,
35 "er, why isn't this a CDATA section node?");
43 var outer = element();
44 var first = text(
"first");
45 var second = element();
46 second.appendChild(text(
"element contents"));
47 outer.appendChild(first);
48 outer.appendChild(second);
50 is(first.wholeText,
"first",
"wrong wholeText for first");
52 var insertedText = text(
"-continued");
53 outer.insertBefore(insertedText, second);
55 is(first.wholeText,
"first-continued",
56 "wrong wholeText for first after insertedText insertion");
57 is(insertedText.wholeText,
"first-continued",
58 "wrong wholeText for insertedText after insertedText insertion");
60 var cdataNode = cdata(
"zero-")
61 outer.insertBefore(cdataNode, first);
63 is(first.wholeText,
"zero-first-continued",
64 "wrong wholeText for first after cdataNode insertion");
65 is(cdataNode.wholeText,
"zero-first-continued",
66 "wrong wholeText for cdataNode after cdataNode insertion");
67 is(insertedText.wholeText,
"zero-first-continued",
68 "wrong wholeText for insertedText after cdataNode insertion");
70 outer.insertBefore(element(), first);
72 is(first.wholeText,
"first-continued",
73 "wrong wholeText for first after element insertion");
74 is(cdataNode.wholeText,
"zero-",
75 "wrong wholeText for cdataNode after element insertion");
76 is(insertedText.wholeText,
"first-continued",
77 "wrong wholeText for insertedText after element insertion");
79 var cdataNode2 = cdata(
"-interrupted");
80 outer.insertBefore(cdataNode2, insertedText);
82 is(first.wholeText,
"first-interrupted-continued",
83 "wrong wholeText for first after cdataNode2 insertion");
84 is(cdataNode2.wholeText,
"first-interrupted-continued",
85 "wrong wholeText for cdataNode2 after cdataNode2 insertion");
86 is(insertedText.wholeText,
"first-interrupted-continued",
87 "wrong wholeText for insertedText after cdataNode2 insertion");
90 function middleTests()
92 var outer = element();
93 var first = element();
95 var middle = text(
"middle");
96 first.appendChild(text(
"first element contents"));
97 last.appendChild(text(
"last element contents"));
98 outer.appendChild(first);
99 outer.appendChild(middle);
100 outer.appendChild(last);
102 is(middle.wholeText,
"middle",
"wrong wholeText for middle");
104 var beforeMiddle = text(
"before-");
105 outer.insertBefore(beforeMiddle, middle);
107 is(middle.wholeText,
"before-middle",
108 "wrong wholeText for middle after beforeMiddle insertion");
109 is(beforeMiddle.wholeText,
"before-middle",
110 "wrong wholeText for beforeMiddle after beforeMiddle insertion");
112 var midElement = element();
113 midElement.appendChild(text(
"middle element"));
114 outer.insertBefore(midElement, middle);
116 is(middle.wholeText,
"middle",
117 "wrong wholeText for middle after midElement insertion");
118 is(beforeMiddle.wholeText,
"before-",
119 "wrong wholeText for beforeMiddle after midElement insertion");
121 var cdataNode = cdata(
"after");
122 outer.insertBefore(cdataNode, midElement);
124 is(cdataNode.wholeText,
"before-after",
125 "wrong wholeText for cdataNode after cdataNode insertion");
126 is(beforeMiddle.wholeText,
"before-after",
127 "wrong wholeText for beforeMiddle after cdataNode insertion");
128 is(middle.wholeText,
"middle",
129 "wrong wholeText for middle after cdataNode insertion");
131 var cdataNode2 = cdata(
"before-");
132 outer.insertBefore(cdataNode2, middle);
134 is(cdataNode.wholeText,
"before-after",
135 "wrong wholeText for cdataNode after cdataNode2 insertion");
136 is(beforeMiddle.wholeText,
"before-after",
137 "wrong wholeText for beforeMiddle after cdataNode2 insertion");
138 is(cdataNode2.wholeText,
"before-middle",
139 "wrong wholeText for middle after cdataNode2 insertion");
140 is(middle.wholeText,
"before-middle",
141 "wrong wholeText for middle after cdataNode2 insertion");
146 var outer = element();
147 var first = element();
148 var second = text(
"second");
149 first.appendChild(text(
"element contents"));
150 outer.appendChild(first);
151 outer.appendChild(second);
153 is(second.wholeText,
"second",
"wrong wholeText for second");
155 var insertedText = text(
"before-");
156 outer.insertBefore(insertedText, second);
158 is(second.wholeText,
"before-second",
159 "wrong wholeText for second after insertedText insertion");
160 is(insertedText.wholeText,
"before-second",
161 "wrong wholeText for insertedText after insertedText insertion");
163 var cdataNode = cdata(
"zero-")
164 outer.insertBefore(cdataNode, insertedText);
166 is(cdataNode.wholeText,
"zero-before-second",
167 "wrong wholeText for cdataNode after cdataNode insertion");
168 is(second.wholeText,
"zero-before-second",
169 "wrong wholeText for second after cdataNode insertion");
170 is(insertedText.wholeText,
"zero-before-second",
171 "wrong wholeText for insertedText after cdataNode insertion");
173 outer.insertBefore(element(), second);
175 is(second.wholeText,
"second",
176 "wrong wholeText for second after element insertion");
177 is(cdataNode.wholeText,
"zero-before-",
178 "wrong wholeText for cdataNode after element insertion");
179 is(insertedText.wholeText,
"zero-before-",
180 "wrong wholeText for insertedText after element insertion");
182 var cdataNode2 = cdata(
"interrupted-");
183 outer.insertBefore(cdataNode2, insertedText);
185 is(second.wholeText,
"second",
186 "wrong wholeText for second after cdataNode2 insertion");
187 is(cdataNode2.wholeText,
"zero-interrupted-before-",
188 "wrong wholeText for cdataNode2 after cdataNode2 insertion");
189 is(insertedText.wholeText,
"zero-interrupted-before-",
190 "wrong wholeText for insertedText after cdataNode2 insertion");
193 function noParentTests()
195 var textNode = text(
"foobar");
196 is(textNode.wholeText, textNode.data,
197 "orphaned textNode should have wholeText == data");
198 is(textNode.wholeText,
"foobar",
199 "orphaned textNode should have wholeText == 'foobar'");
201 var cdataSection = cdata(
"baz");
202 is(cdataSection.wholeText, cdataSection.data,
203 "orphaned cdatasection should have wholeText == data");
204 is(cdataSection.wholeText,
"baz",
205 "orphaned cdatasection should have wholeText == data");
219 ok(false,
"error thrown: " + e);
227 window.addEventListener(
"load", tests);