Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/Node/textContent.html

Issue 2415923003: Fix setting textContent to empty string (Closed)
Patch Set: Remove test Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/dom/Node/textContent-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/testharness.js"></script>
5 <script src="../../../resources/testharnessreport.js"></script>
6 </head>
7 <body>
8 <script>
9 var documents, doctypes;
10 setup(function() {
11 documents = [
12 [document, "parser"],
13 [document.implementation.createDocument("", "test", null), "createDocume nt"],
14 [document.implementation.createHTMLDocument("title"), "createHTMLDocumen t"],
15 ]
16 doctypes = [
17 [document.doctype, "parser"],
18 [document.implementation.createDocumentType("x", "", ""), "script"],
19 ]
20 });
21
22 // Getting
23 // DocumentFragment, Element:
24 test(function() {
25 var element = document.createElement("div");
26 assert_equals(element.textContent, "");
27 }, "For an empty Element, textContent should be the empty string");
28
29 test(function() {
30 assert_equals(document.createDocumentFragment().textContent, "");
31 }, "For an empty DocumentFragment, textContent should be the empty string");
32
33 test(function() {
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");
40
41 test(function() {
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");
50
51 test(function() {
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");
58
59 test(function() {
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");
68
69 // Text, ProcessingInstruction, Comment:
70 test(function() {
71 assert_equals(document.createTextNode("").textContent, "");
72 }, "For an empty Text, textContent should be the empty string");
73
74 test(function() {
75 assert_equals(document.createProcessingInstruction("x", "").textContent, "") ;
76 }, "For an empty ProcessingInstruction, textContent should be the empty string") ;
77
78 test(function() {
79 assert_equals(document.createComment("").textContent, "");
80 }, "For an empty Comment, textContent should be the empty string");
81
82 test(function() {
83 assert_equals(document.createTextNode("abc").textContent, "abc");
84 }, "For a Text with data, textContent should be that data");
85
86 test(function() {
87 assert_equals(document.createProcessingInstruction("x", "abc").textContent, "abc");
88 }, "For a ProcessingInstruction with data, textContent should be that data");
89
90 test(function() {
91 assert_equals(document.createComment("abc").textContent, "abc");
92 }, "For a Comment with data, textContent should be that data");
93
94 // Any other node:
95 documents.forEach(function(argument) {
96 var doc = argument[0], creator = argument[1];
97 test(function() {
98 assert_equals(doc.textContent, null);
99 }, "For Documents created by " + creator + ", textContent should be null");
100 });
101
102 doctypes.forEach(function(argument) {
103 var doctype = argument[0], creator = argument[1];
104 test(function() {
105 assert_equals(doctype.textContent, null);
106 }, "For DocumentType created by " + creator + ", textContent should be null" );
107 });
108
109 // Setting
110 // DocumentFragment, Element:
111 var arguments = [
112 [null, null],
113 [undefined, null],
114 ["", null],
115 [42, "42"],
116 ["abc", "abc"],
117 ["<b>xyz<\/b>", "<b>xyz<\/b>"],
118 ["d\0e", "d\0e"]
119 // XXX unpaired surrogate?
120 ]
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);
127 } else {
128 assert_equals(aElementOrDocumentFragment.textContent, expectation);
129 assert_equals(aElementOrDocumentFragment.childNodes.length, 1, "Shou ld 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);
133 }
134 }
135
136 test(function() {
137 var el = document.createElement("div");
138 el.textContent = argument;
139 check(el);
140 }, "Element without children set to " + format_value(argument));
141
142 test(function() {
143 var el = document.createElement("div");
144 var text = el.appendChild(document.createTextNode(""));
145 el.textContent = argument;
146 check(el);
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)) ;
149
150 test(function() {
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;
156 check(el);
157 }, "Element with children set to " + format_value(argument));
158
159 test(function() {
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;
167 check(el);
168 assert_equals(child.childNodes.length, 3, "Should not have changed the i nternal structure of the removed nodes.");
169 }, "Element with descendants set to " + format_value(argument));
170
171 test(function() {
172 var df = document.createDocumentFragment();
173 df.textContent = argument;
174 check(df);
175 }, "DocumentFragment without children set to " + format_value(argument));
176
177 test(function() {
178 var df = document.createDocumentFragment();
179 var text = df.appendChild(document.createTextNode(""));
180 df.textContent = argument;
181 check(df);
182 assert_equals(text.parentNode, null, "Preexisting Text should have been removed");
183 }, "DocumentFragment with empty text node as child set to " + format_value(a rgument));
184
185 test(function() {
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;
191 check(df);
192 }, "DocumentFragment with children set to " + format_value(argument));
193
194 test(function() {
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;
202 check(df);
203 assert_equals(child.childNodes.length, 3, "Should not have changed the i nternal structure of the removed nodes.");
204 }, "DocumentFragment with descendants set to " + format_value(argument));
205 })
206
207 // Text, ProcessingInstruction, Comment:
208 test(function() {
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");
214
215 test(function() {
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");
222
223 test(function() {
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");
229
230 // Any other node:
231 documents.forEach(function(argument) {
232 var doc = argument[0], creator = argument[1];
233 test(function() {
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");
239 });
240
241 doctypes.forEach(function(argument) {
242 var doctype = argument[0], creator = argument[1];
243 test(function() {
244 var props = {
245 name: doctype.name,
246 publicId: doctype.publicId,
247 systemId: doctype.systemId,
248 }
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 cha nge");
253 assert_equals(doctype.systemId, props.systemId, "systemId should not cha nge");
254 }, "For DocumentType created by " + creator + ", setting textContent should do nothing");
255 });
256 </script>
257 </body>
258 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/dom/Node/textContent-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698