4 <title>DOM Traversal: NodeIterator: Mutations (
3/x)
</title>
7 <div id=
"content" style=
"display: none">
8 <span id=root
><span id=B
></span><span id=C
></span><span id=D
></span><span id=E
><span id=E1
><span id=E11
></span></span></span></span>
11 Results available in the JavaScript console
12 Test adapted from http://mxr.mozilla.org/mozilla-central/source/content/base/test/test_NodeIterator_mutations_3.html
13 <script class=
"testbody" type=
"text/javascript">
14 if (window.testRunner)
15 testRunner.dumpAsText();
18 return document.getElementById(id);
21 function removeNode(n) {
22 n.parentNode.removeChild(n);
24 var initInner = $('content').innerHTML;
25 var content = $('content');
27 function resetContent() {
28 content.innerHTML = initInner;
29 var checkIt = document.createNodeIterator(content, NodeFilter.SHOW_ELEMENT, testNodeFilter, false);
31 while ((node = checkIt.nextNode()) != null) {
33 window[node.id] = node;
38 function makeSpan(id) {
39 var e = document.createElement('span');
44 function testNodeFilter(n) {
45 if (n.tagName == 'SPAN')
46 return NodeFilter.FILTER_ACCEPT;
47 return NodeFilter.FILTER_SKIP;
50 function checkseq(it, root, expect) {
51 var checkIt = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, testNodeFilter, false);
52 var printedPointer = (it.referenceNode == undefined);
55 while ((node = checkIt.nextNode()) != null) {
56 if (!printedPointer && it.referenceNode == node) {
57 printedPointer = true;
58 var s = '[' + node.id + '] ';
59 if (it.pointerBeforeReferenceNode)
64 string += node.id +
" ";
67 console.log(
"sequence check:");
68 console.log(string.slice(
0, -
1) +
" (actual)");
69 console.log(expect +
" (expected)");
73 var it = document.createNodeIterator(E, NodeFilter.SHOW_ELEMENT,
74 testNodeFilter, false);
75 checkseq(it, root,
"root B C D * [E] E1 E11");
78 checkseq(it, root,
"root B D * [E] E1 E11");
82 checkseq(it, root,
"root B [E] * E1 E11");
86 checkseq(it, root,
"root E [E1] * E11");
89 checkseq(it, root,
"root E E1 [E11] *");
92 checkseq(it, root,
"root E E1 [E11] *");
99 checkseq(it, root,
"root * [E] E1 E11");
102 it = document.createNodeIterator(E, NodeFilter.SHOW_ELEMENT,
103 testNodeFilter, false);
104 checkseq(it, root,
"root B C D * [E] E1 E11");
108 checkseq(it, root,
"root B C D E [E1] * E11");
112 checkseq(it, root,
"root B C D * [E] E1 E11");
116 checkseq(it, root,
"root C * [E] E1 E11");
119 root.insertBefore(n, E);
120 checkseq(it, root,
"root C n * [E] E1 E11");
123 root.insertBefore(n2, C);
124 checkseq(it, root,
"root n2 C n * [E] E1 E11");
127 it = document.createNodeIterator(E, NodeFilter.SHOW_ELEMENT,
128 testNodeFilter, false);
129 checkseq(it, root,
"root B C D * [E] E1 E11");
132 checkseq(it, root,
"root B C D * [E] E1 E11");
135 checkseq(it, root,
"root C D * [E] E1 E11");
138 checkseq(it, root,
"root C * [E] E1 E11");
143 checkseq(it, root,
"root C E E1 [E11] *");
146 checkseq(it, root,
"root C [E] *");
149 root.insertBefore(n, E);
150 checkseq(it, root,
"root C n [E] *");
154 checkseq(it, root,
"root C n [E] * n2");
157 checkseq(it, root,
"root C n E [n2] *");
160 checkseq(it, root,
"root C n");