4 <script src=
"../../../resources/testharness.js"></script>
5 <script src=
"../../../resources/testharnessreport.js"></script>
9 var documents
, doctypes
;
13 [document
.implementation
.createDocument("", "test", null), "createDocument"],
14 [document
.implementation
.createHTMLDocument("title"), "createHTMLDocument"],
17 [document
.doctype
, "parser"],
18 [document
.implementation
.createDocumentType("x", "", ""), "script"],
23 // DocumentFragment, Element:
25 var element
= document
.createElement("div");
26 assert_equals(element
.textContent
, "");
27 }, "For an empty Element, textContent should be the empty string");
30 assert_equals(document
.createDocumentFragment().textContent
, "");
31 }, "For an empty DocumentFragment, textContent should be the empty string");
34 var el
= document
.createElement("div");
35 el
.appendChild(document
.createComment(" abc "));
36 el
.appendChild(document
.createTextNode("\tDEF\t"));
37 el
.appendChild(document
.createProcessingInstruction("x", " ghi "));
38 assert_equals(el
.textContent
, "\tDEF\t");
39 }, "Element with children");
42 var el
= document
.createElement("div");
43 var child
= document
.createElement("div");
44 el
.appendChild(child
);
45 child
.appendChild(document
.createComment(" abc "));
46 child
.appendChild(document
.createTextNode("\tDEF\t"));
47 child
.appendChild(document
.createProcessingInstruction("x", " ghi "));
48 assert_equals(el
.textContent
, "\tDEF\t");
49 }, "Element with descendants");
52 var df
= document
.createDocumentFragment();
53 df
.appendChild(document
.createComment(" abc "));
54 df
.appendChild(document
.createTextNode("\tDEF\t"));
55 df
.appendChild(document
.createProcessingInstruction("x", " ghi "));
56 assert_equals(df
.textContent
, "\tDEF\t");
57 }, "DocumentFragment with children");
60 var df
= document
.createDocumentFragment();
61 var child
= document
.createElement("div");
62 df
.appendChild(child
);
63 child
.appendChild(document
.createComment(" abc "));
64 child
.appendChild(document
.createTextNode("\tDEF\t"));
65 child
.appendChild(document
.createProcessingInstruction("x", " ghi "));
66 assert_equals(df
.textContent
, "\tDEF\t");
67 }, "DocumentFragment with descendants");
69 // Text, ProcessingInstruction, Comment:
71 assert_equals(document
.createTextNode("").textContent
, "");
72 }, "For an empty Text, textContent should be the empty string");
75 assert_equals(document
.createProcessingInstruction("x", "").textContent
, "");
76 }, "For an empty ProcessingInstruction, textContent should be the empty string");
79 assert_equals(document
.createComment("").textContent
, "");
80 }, "For an empty Comment, textContent should be the empty string");
83 assert_equals(document
.createTextNode("abc").textContent
, "abc");
84 }, "For a Text with data, textContent should be that data");
87 assert_equals(document
.createProcessingInstruction("x", "abc").textContent
, "abc");
88 }, "For a ProcessingInstruction with data, textContent should be that data");
91 assert_equals(document
.createComment("abc").textContent
, "abc");
92 }, "For a Comment with data, textContent should be that data");
95 documents
.forEach(function(argument
) {
96 var doc
= argument
[0], creator
= argument
[1];
98 assert_equals(doc
.textContent
, null);
99 }, "For Documents created by " + creator
+ ", textContent should be null");
102 doctypes
.forEach(function(argument
) {
103 var doctype
= argument
[0], creator
= argument
[1];
105 assert_equals(doctype
.textContent
, null);
106 }, "For DocumentType created by " + creator
+ ", textContent should be null");
110 // DocumentFragment, Element:
117 ["<b>xyz<\/b>", "<b>xyz<\/b>"],
119 // XXX unpaired surrogate?
121 arguments
.forEach(function(aValue
) {
122 var argument
= aValue
[0], expectation
= aValue
[1];
123 var check = function(aElementOrDocumentFragment
) {
124 if (expectation
=== null) {
125 assert_equals(aElementOrDocumentFragment
.textContent
, "");
126 assert_equals(aElementOrDocumentFragment
.firstChild
, null);
128 assert_equals(aElementOrDocumentFragment
.textContent
, expectation
);
129 assert_equals(aElementOrDocumentFragment
.childNodes
.length
, 1, "Should have one child");
130 var firstChild
= aElementOrDocumentFragment
.firstChild
;
131 assert_true(firstChild
instanceof Text
, "child should be a Text");
132 assert_equals(firstChild
.data
, expectation
);
137 var el
= document
.createElement("div");
138 el
.textContent
= argument
;
140 }, "Element without children set to " + format_value(argument
));
143 var el
= document
.createElement("div");
144 var text
= el
.appendChild(document
.createTextNode(""));
145 el
.textContent
= argument
;
147 assert_equals(text
.parentNode
, null, "Preexisting Text should have been removed");
148 }, "Element with empty text node as child set to " + format_value(argument
));
151 var el
= document
.createElement("div");
152 el
.appendChild(document
.createComment(" abc "));
153 el
.appendChild(document
.createTextNode("\tDEF\t"));
154 el
.appendChild(document
.createProcessingInstruction("x", " ghi "));
155 el
.textContent
= argument
;
157 }, "Element with children set to " + format_value(argument
));
160 var el
= document
.createElement("div");
161 var child
= document
.createElement("div");
162 el
.appendChild(child
);
163 child
.appendChild(document
.createComment(" abc "));
164 child
.appendChild(document
.createTextNode("\tDEF\t"));
165 child
.appendChild(document
.createProcessingInstruction("x", " ghi "));
166 el
.textContent
= argument
;
168 assert_equals(child
.childNodes
.length
, 3, "Should not have changed the internal structure of the removed nodes.");
169 }, "Element with descendants set to " + format_value(argument
));
172 var df
= document
.createDocumentFragment();
173 df
.textContent
= argument
;
175 }, "DocumentFragment without children set to " + format_value(argument
));
178 var df
= document
.createDocumentFragment();
179 var text
= df
.appendChild(document
.createTextNode(""));
180 df
.textContent
= argument
;
182 assert_equals(text
.parentNode
, null, "Preexisting Text should have been removed");
183 }, "DocumentFragment with empty text node as child set to " + format_value(argument
));
186 var df
= document
.createDocumentFragment();
187 df
.appendChild(document
.createComment(" abc "));
188 df
.appendChild(document
.createTextNode("\tDEF\t"));
189 df
.appendChild(document
.createProcessingInstruction("x", " ghi "));
190 df
.textContent
= argument
;
192 }, "DocumentFragment with children set to " + format_value(argument
));
195 var df
= document
.createDocumentFragment();
196 var child
= document
.createElement("div");
197 df
.appendChild(child
);
198 child
.appendChild(document
.createComment(" abc "));
199 child
.appendChild(document
.createTextNode("\tDEF\t"));
200 child
.appendChild(document
.createProcessingInstruction("x", " ghi "));
201 df
.textContent
= argument
;
203 assert_equals(child
.childNodes
.length
, 3, "Should not have changed the internal structure of the removed nodes.");
204 }, "DocumentFragment with descendants set to " + format_value(argument
));
207 // Text, ProcessingInstruction, Comment:
209 var text
= document
.createTextNode("abc");
210 text
.textContent
= "def";
211 assert_equals(text
.textContent
, "def");
212 assert_equals(text
.data
, "def");
213 }, "For a Text, textContent should set the data");
216 var pi
= document
.createProcessingInstruction("x", "abc");
217 pi
.textContent
= "def";
218 assert_equals(pi
.textContent
, "def");
219 assert_equals(pi
.data
, "def");
220 assert_equals(pi
.target
, "x");
221 }, "For a ProcessingInstruction, textContent should set the data");
224 var comment
= document
.createComment("abc");
225 comment
.textContent
= "def";
226 assert_equals(comment
.textContent
, "def");
227 assert_equals(comment
.data
, "def");
228 }, "For a Comment, textContent should set the data");
231 documents
.forEach(function(argument
) {
232 var doc
= argument
[0], creator
= argument
[1];
234 var root
= doc
.documentElement
;
235 doc
.textContent
= "a";
236 assert_equals(doc
.textContent
, null);
237 assert_equals(doc
.documentElement
, root
);
238 }, "For Documents created by " + creator
+ ", setting textContent should do nothing");
241 doctypes
.forEach(function(argument
) {
242 var doctype
= argument
[0], creator
= argument
[1];
246 publicId
: doctype
.publicId
,
247 systemId
: doctype
.systemId
,
249 doctype
.textContent
= "b";
250 assert_equals(doctype
.textContent
, null);
251 assert_equals(doctype
.name
, props
.name
, "name should not change");
252 assert_equals(doctype
.publicId
, props
.publicId
, "publicId should not change");
253 assert_equals(doctype
.systemId
, props
.systemId
, "systemId should not change");
254 }, "For DocumentType created by " + creator
+ ", setting textContent should do nothing");