Chromium Code Reviews| OLD | NEW |
|---|---|
| (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") | |
|
haraken
2014/07/12 15:46:13
Nit: We normally add ';' to each statement.
kangil_
2014/07/12 16:12:09
Done.
| |
| 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, | |
| 130 "Should have one child") | |
| 131 var firstChild = aElementOrDocumentFragment.firstChild | |
| 132 assert_true(firstChild instanceof Text, "child should be a Text") | |
| 133 assert_equals(firstChild.data, expectation) | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 test(function() { | |
| 138 var el = document.createElement("div") | |
| 139 el.textContent = argument | |
| 140 check(el) | |
| 141 }, "Element without children set to " + format_value(argument)) | |
| 142 | |
| 143 test(function() { | |
| 144 var el = document.createElement("div") | |
| 145 var text = el.appendChild(document.createTextNode("")) | |
| 146 el.textContent = argument | |
| 147 check(el) | |
| 148 assert_equals(text.parentNode, null, "Preexisting Text should have been removed") | |
| 149 }, "Element with empty text node as child set to " + format_value(argument)) | |
| 150 | |
| 151 test(function() { | |
| 152 var el = document.createElement("div") | |
| 153 el.appendChild(document.createComment(" abc ")) | |
| 154 el.appendChild(document.createTextNode("\tDEF\t")) | |
| 155 el.appendChild(document.createProcessingInstruction("x", " ghi ")) | |
| 156 el.textContent = argument | |
| 157 check(el) | |
| 158 }, "Element with children set to " + format_value(argument)) | |
| 159 | |
| 160 test(function() { | |
| 161 var el = document.createElement("div") | |
| 162 var child = document.createElement("div") | |
| 163 el.appendChild(child) | |
| 164 child.appendChild(document.createComment(" abc ")) | |
| 165 child.appendChild(document.createTextNode("\tDEF\t")) | |
| 166 child.appendChild(document.createProcessingInstruction("x", " ghi ")) | |
| 167 el.textContent = argument | |
| 168 check(el) | |
| 169 assert_equals(child.childNodes.length, 3, "Should not have changed the i nternal structure of the removed nodes.") | |
| 170 }, "Element with descendants set to " + format_value(argument)) | |
| 171 | |
| 172 test(function() { | |
| 173 var df = document.createDocumentFragment() | |
| 174 df.textContent = argument | |
| 175 check(df) | |
| 176 }, "DocumentFragment without children set to " + format_value(argument)) | |
| 177 | |
| 178 test(function() { | |
| 179 var df = document.createDocumentFragment() | |
| 180 var text = df.appendChild(document.createTextNode("")) | |
| 181 df.textContent = argument | |
| 182 check(df) | |
| 183 assert_equals(text.parentNode, null, "Preexisting Text should have been removed") | |
| 184 }, "DocumentFragment with empty text node as child set to " + format_value(a rgument)) | |
| 185 | |
| 186 test(function() { | |
| 187 var df = document.createDocumentFragment() | |
| 188 df.appendChild(document.createComment(" abc ")) | |
| 189 df.appendChild(document.createTextNode("\tDEF\t")) | |
| 190 df.appendChild(document.createProcessingInstruction("x", " ghi ")) | |
| 191 df.textContent = argument | |
| 192 check(df) | |
| 193 }, "DocumentFragment with children set to " + format_value(argument)) | |
| 194 | |
| 195 test(function() { | |
| 196 var df = document.createDocumentFragment() | |
| 197 var child = document.createElement("div") | |
| 198 df.appendChild(child) | |
| 199 child.appendChild(document.createComment(" abc ")) | |
| 200 child.appendChild(document.createTextNode("\tDEF\t")) | |
| 201 child.appendChild(document.createProcessingInstruction("x", " ghi ")) | |
| 202 df.textContent = argument | |
| 203 check(df) | |
| 204 assert_equals(child.childNodes.length, 3, "Should not have changed the i nternal structure of the removed nodes.") | |
| 205 }, "DocumentFragment with descendants set to " + format_value(argument)) | |
| 206 }) | |
| 207 | |
| 208 // Text, ProcessingInstruction, Comment: | |
| 209 test(function() { | |
| 210 var text = document.createTextNode("abc") | |
| 211 text.textContent = "def" | |
| 212 assert_equals(text.textContent, "def") | |
| 213 assert_equals(text.data, "def") | |
| 214 }, "For a Text, textContent should set the data") | |
| 215 | |
| 216 test(function() { | |
| 217 var pi = document.createProcessingInstruction("x", "abc") | |
| 218 pi.textContent = "def" | |
| 219 assert_equals(pi.textContent, "def") | |
| 220 assert_equals(pi.data, "def") | |
| 221 assert_equals(pi.target, "x") | |
| 222 }, "For a ProcessingInstruction, textContent should set the data") | |
| 223 | |
| 224 test(function() { | |
| 225 var comment = document.createComment("abc") | |
| 226 comment.textContent = "def" | |
| 227 assert_equals(comment.textContent, "def") | |
| 228 assert_equals(comment.data, "def") | |
| 229 }, "For a Comment, textContent should set the data") | |
| 230 | |
| 231 // Any other node: | |
| 232 documents.forEach(function(argument) { | |
| 233 var doc = argument[0], creator = argument[1] | |
| 234 test(function() { | |
| 235 var root = doc.documentElement | |
| 236 doc.textContent = "a" | |
| 237 assert_equals(doc.textContent, null) | |
| 238 assert_equals(doc.documentElement, root) | |
| 239 }, "For Documents created by " + creator + ", setting textContent should do nothing") | |
| 240 }) | |
| 241 | |
| 242 doctypes.forEach(function(argument) { | |
| 243 var doctype = argument[0], creator = argument[1] | |
| 244 test(function() { | |
| 245 var props = { | |
| 246 name: doctype.name, | |
| 247 publicId: doctype.publicId, | |
| 248 systemId: doctype.systemId, | |
| 249 } | |
| 250 doctype.textContent = "b" | |
| 251 assert_equals(doctype.textContent, null) | |
| 252 assert_equals(doctype.name, props.name, "name should not change") | |
| 253 assert_equals(doctype.publicId, props.publicId, "publicId should not cha nge") | |
| 254 assert_equals(doctype.systemId, props.systemId, "systemId should not cha nge") | |
| 255 }, "For DocumentType created by " + creator + ", setting textContent should do nothing") | |
| 256 }) | |
| 257 </script> | |
| 258 </body> | |
| 259 </html> | |
| OLD | NEW |