Node-removeChild.html (2094B)
1 <!DOCTYPE html> 2 <title>Node.removeChild</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="creators.js"></script> 6 <div id="log"></div> 7 <iframe src=about:blank></iframe> 8 <script> 9 var documents = [ 10 [function() { return document }, "the main document"], 11 [function() { return frames[0].document }, "a frame document"], 12 [function() { return document.implementation.createHTMLDocument() }, 13 "a synthetic document"], 14 ]; 15 16 documents.forEach(function(d) { 17 var get = d[0], description = d[1] 18 for (var p in creators) { 19 var creator = creators[p]; 20 test(function() { 21 var doc = get(); 22 var s = doc[creator]("a") 23 assert_equals(s.ownerDocument, doc) 24 assert_throws_dom("NOT_FOUND_ERR", function() { document.body.removeChild(s) }) 25 assert_equals(s.ownerDocument, doc) 26 }, "Passing a detached " + p + " from " + description + 27 " to removeChild should not affect it.") 28 29 test(function() { 30 var doc = get(); 31 var s = doc[creator]("b") 32 doc.documentElement.appendChild(s) 33 assert_equals(s.ownerDocument, doc) 34 assert_throws_dom("NOT_FOUND_ERR", function() { document.body.removeChild(s) }) 35 assert_equals(s.ownerDocument, doc) 36 }, "Passing a non-detached " + p + " from " + description + 37 " to removeChild should not affect it.") 38 39 test(function() { 40 var doc = get(); 41 var s = doc[creator]("test") 42 doc.body.appendChild(s) 43 assert_equals(s.ownerDocument, doc) 44 assert_throws_dom( 45 "NOT_FOUND_ERR", 46 (doc.defaultView || self).DOMException, 47 function() { s.removeChild(doc) } 48 ); 49 }, "Calling removeChild on a " + p + " from " + description + 50 " with no children should throw NOT_FOUND_ERR.") 51 } 52 }); 53 54 test(function() { 55 assert_throws_js(TypeError, function() { document.body.removeChild(null) }) 56 assert_throws_js(TypeError, function() { document.body.removeChild({'a':'b'}) }) 57 }, "Passing a value that is not a Node reference to removeChild should throw TypeError.") 58 </script>