script-text.html (2379B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>HTMLScriptElement.text</title> 4 <link rel=help href="https://html.spec.whatwg.org/multipage/#dom-script-text"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <div id="log"></div> 8 <script> 9 var script; 10 setup(function() { 11 script = document.createElement("script") 12 script.appendChild(document.createComment("COMMENT")) 13 script.appendChild(document.createTextNode(" TEXT ")) 14 script.appendChild(document.createProcessingInstruction("P", "I")) 15 script.appendChild(document.createElement("a")) 16 .appendChild(document.createTextNode("ELEMENT")) 17 }) 18 19 test(function() { 20 assert_equals(script.text, " TEXT ") 21 assert_equals(script.textContent, " TEXT ELEMENT") 22 }, "Getter") 23 24 test(function() { 25 script.text = " text " 26 assert_equals(script.text, " text ") 27 assert_equals(script.textContent, " text ") 28 assert_equals(script.firstChild.nodeType, Node.TEXT_NODE) 29 assert_equals(script.firstChild.data, " text ") 30 assert_equals(script.firstChild, script.lastChild) 31 assert_array_equals(script.childNodes, [script.firstChild]) 32 }, "Setter (non-empty string)") 33 34 test(function() { 35 script.text = "" 36 assert_equals(script.text, "") 37 assert_equals(script.textContent, "") 38 assert_equals(script.firstChild, null) 39 }, "Setter (empty string)") 40 41 test(function() { 42 script.text = null 43 assert_equals(script.text, "null") 44 assert_equals(script.textContent, "null") 45 assert_equals(script.firstChild.nodeType, Node.TEXT_NODE) 46 assert_equals(script.firstChild.data, "null") 47 assert_equals(script.firstChild, script.lastChild) 48 }, "Setter (null)") 49 50 test(function() { 51 script.text = undefined 52 assert_equals(script.text, "undefined") 53 assert_equals(script.textContent, "undefined") 54 assert_equals(script.firstChild.nodeType, Node.TEXT_NODE) 55 assert_equals(script.firstChild.data, "undefined") 56 assert_equals(script.firstChild, script.lastChild) 57 }, "Setter (undefined)") 58 59 test(function() { 60 var s = document.createElement("script"); 61 var text = document.createTextNode("one"); 62 s.appendChild(text); 63 64 assert_equals(s.firstChild, text); 65 assert_equals(text.nodeValue, "one"); 66 67 s.text = "two"; 68 assert_not_equals(s.firstChild, text); 69 assert_equals(text.nodeValue, "one"); 70 assert_equals(s.firstChild.nodeValue, "two"); 71 }, "Setter (text node reuse)") 72 </script>