OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <title>NodeIterator removal tests</title> |
| 3 <link rel="author" title="Aryeh Gregor" href=ayg@aryeh.name> |
| 4 <meta name=timeout content=long> |
| 5 <div id=log></div> |
| 6 <script src=../../../../resources/testharness.js></script> |
| 7 <script src=../../../../resources/testharnessreport.js></script> |
| 8 <script src=../common.js></script> |
| 9 <script> |
| 10 "use strict"; |
| 11 |
| 12 for (var i = 0; i < testNodes.length; i++) { |
| 13 var node = eval(testNodes[i]); |
| 14 if (!node.parentNode) { |
| 15 // Nothing to test |
| 16 continue; |
| 17 } |
| 18 test(function() { |
| 19 var iters = []; |
| 20 var descs = []; |
| 21 var expectedReferenceNodes = []; |
| 22 var expectedPointers = []; |
| 23 |
| 24 for (var j = 0; j < testNodes.length; j++) { |
| 25 var root = eval(testNodes[j]); |
| 26 // Add all distinct iterators with this root, calling nextNode() |
| 27 // repeatedly until it winds up with the same iterator. |
| 28 for (var k = 0; ; k++) { |
| 29 var iter = document.createNodeIterator(root); |
| 30 for (var l = 0; l < k; l++) { |
| 31 iter.nextNode(); |
| 32 } |
| 33 if (k && iter.referenceNode == iters[iters.length - 1].referenceNode |
| 34 && iter.pointerBeforeReferenceNode |
| 35 == iters[iters.length - 1].pointerBeforeReferenceNode) { |
| 36 break; |
| 37 } else { |
| 38 iters.push(iter); |
| 39 descs.push("document.createNodeIterator(" + testNodes[j] |
| 40 + ") advanced " + k + " times"); |
| 41 expectedReferenceNodes.push(iter.referenceNode); |
| 42 expectedPointers.push(iter.pointerBeforeReferenceNode); |
| 43 |
| 44 var idx = iters.length - 1; |
| 45 |
| 46 // "If the node is root or is not an inclusive ancestor of the |
| 47 // referenceNode attribute value, terminate these steps." |
| 48 // |
| 49 // We also have to rule out the case where node is an ancestor of |
| 50 // root, which is implicitly handled by the spec since such a node |
| 51 // was not part of the iterator collection to start with. |
| 52 if (isInclusiveAncestor(node, root) |
| 53 || !isInclusiveAncestor(node, iter.referenceNode)) { |
| 54 continue; |
| 55 } |
| 56 |
| 57 // "If the pointerBeforeReferenceNode attribute value is false, set |
| 58 // the referenceNode attribute to the first node preceding the node |
| 59 // that is being removed, and terminate these steps." |
| 60 if (!iter.pointerBeforeReferenceNode) { |
| 61 expectedReferenceNodes[idx] = previousNode(node); |
| 62 continue; |
| 63 } |
| 64 |
| 65 // "If there is a node following the last inclusive descendant of the |
| 66 // node that is being removed, set the referenceNode attribute to the |
| 67 // first such node, and terminate these steps." |
| 68 var next = nextNodeDescendants(node); |
| 69 if (next) { |
| 70 expectedReferenceNodes[idx] = next; |
| 71 continue; |
| 72 } |
| 73 |
| 74 // "Set the referenceNode attribute to the first node preceding the |
| 75 // node that is being removed and set the pointerBeforeReferenceNode |
| 76 // attribute to false." |
| 77 expectedReferenceNodes[idx] = previousNode(node); |
| 78 expectedPointers[idx] = false; |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 var oldParent = node.parentNode; |
| 84 var oldSibling = node.nextSibling; |
| 85 oldParent.removeChild(node); |
| 86 |
| 87 for (var j = 0; j < iters.length; j++) { |
| 88 var iter = iters[j]; |
| 89 assert_equals(iter.referenceNode, expectedReferenceNodes[j], |
| 90 ".referenceNode of " + descs[j]); |
| 91 assert_equals(iter.pointerBeforeReferenceNode, expectedPointers[j], |
| 92 ".pointerBeforeReferenceNode of " + descs[j]); |
| 93 } |
| 94 |
| 95 oldParent.insertBefore(node, oldSibling); |
| 96 }, "Test removing node " + testNodes[i]); |
| 97 } |
| 98 |
| 99 testDiv.style.display = "none"; |
| 100 </script> |
OLD | NEW |