003.xml (2135B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>DOM Traversal: NodeIterator: Removal of nodes that should have no effect</title> 4 <!-- 5 This tests these cases that should have no effect: 6 1. Remove a node unrelated to the reference node 7 2. Remove an ancestor of the root node 8 3. Remove the root node itself 9 4. Remove descendant of reference node 10 --> 11 <script type="text/javascript"> <![CDATA[ 12 var errors = 0; 13 var log = ''; 14 function doTest() { 15 var iterator = document.createNodeIterator(document.getElementById('root'), NodeFilter.SHOW_ALL, null, false); 16 var root = document.getElementById('root'); 17 var A = document.getElementById('A'); 18 var B = document.getElementById('B'); 19 var C = document.getElementById('C'); 20 var D = document.getElementById('D'); 21 var E = document.getElementById('E'); 22 check(iterator.nextNode(), root); 23 remove(document.getElementById('X')); 24 check(iterator.nextNode(), A); 25 remove(document.getElementById('Y')); 26 check(iterator.nextNode(), B); 27 remove(root); 28 check(iterator.nextNode(), C); 29 remove(E); 30 check(iterator.nextNode(), D); 31 if (errors) 32 document.getElementById('result').firstChild.data = 'FAIL: ' + errors + ' errors:\n' + log; 33 else 34 document.getElementById('result').firstChild.data = 'PASS'; 35 } 36 function check(a, b) { 37 if (!a) { 38 errors += 1; 39 log += 'Found null but expected ' + b + ' (' + b.id + ').\n'; 40 } else if (a != b) { 41 errors += 1; 42 log += 'Found ' + a + ' (' + a.id + ') but expected ' + b + ' (' + b.id + ').\n'; 43 } 44 } 45 function remove(a) { 46 if (!a) { 47 errors += 1; 48 log += 'Tried removing null node.\n'; 49 } else 50 a.parentNode.removeChild(a); 51 } 52 ]]></script> 53 </head> 54 <body onload="doTest()"> 55 <pre id="result">FAIL: Script did not complete.</pre> 56 <p><span id="X"></span><span id="Y"><span id="root"><span id="A"><span id="B"><span id="C"><span id="D"><span id="E"></span></span></span></span></span></span></span></p> 57 </body> 58 </html>