1 description("Test of behavior NodeIterator when nodes are removed, from Acid3.");
3 var iframe = document.createElement("iframe");
4 iframe.setAttribute("src", "about:blank");
5 document.body.appendChild(iframe);
6 var doc = iframe.contentDocument;
7 for (var i = doc.documentElement.childNodes.length-1; i >= 0; i -= 1)
8 doc.documentElement.removeChild(doc.documentElement.childNodes[i]);
9 doc.documentElement.appendChild(doc.createElement('head'));
10 doc.documentElement.firstChild.appendChild(doc.createElement('title'));
11 doc.documentElement.appendChild(doc.createElement('body'));
13 // test 2: Removing nodes during iteration
15 var t1 = doc.body.appendChild(doc.createElement('t1'));
16 var t2 = doc.body.appendChild(doc.createElement('t2'));
17 var t3 = doc.body.appendChild(doc.createElement('t3'));
18 var t4 = doc.body.appendChild(doc.createElement('t4'));
19 var expect = function(n, node1, node2) {
21 shouldBe("count", "" + n);
24 shouldBe("nodea", "nodeb");
27 var filterFunctions = [
28 function (node) { expect(1, node, doc.body); return true; }, // filter 0
29 function (node) { expect(3, node, t1); return true; }, // filter 1
30 function (node) { expect(5, node, t2); return true; }, // filter 2
31 function (node) { expect(7, node, t3); doc.body.removeChild(t4); return true; }, // filter 3
32 function (node) { expect(9, node, t4); return true; }, // filter 4
33 function (node) { expect(11, node, t4); doc.body.removeChild(t4); return 2 /* REJECT */; }, // filter 5
34 function (node) { expect(12, node, t3); return true; }, // filter 6
35 function (node) { expect(14, node, t2); doc.body.removeChild(t2); return true; }, // filter 7
36 function (node) { expect(16, node, t1); return true; }, // filter 8
38 var i = doc.createNodeIterator(doc.documentElement.lastChild, 0xFFFFFFFF, function (node) { return filterFunctions[callCount++](node); }, true);
40 expect(2, i.nextNode(), doc.body); // filter 0
42 expect(4, i.nextNode(), t1); // filter 1
44 expect(6, i.nextNode(), t2); // filter 2
46 expect(8, i.nextNode(), t3); // filter 3
48 doc.body.appendChild(t4);
50 expect(10, i.nextNode(), t4); // filter 4
52 expect(13, i.previousNode(), t3); // filters 5, 6
53 // B 1 2 3 * (4) // filter 5
54 // B 1 2 [3] * // between 5 and 6
55 // B 1 2 * (3) // filter 6
57 expect(15, i.previousNode(), t2); // filter 7
59 // -- spec says "For instance, if a NodeFilter removes a node
60 // from a document, it can still accept the node, which
61 // means that the node may be returned by the NodeIterator
62 // or TreeWalker even though it is no longer in the subtree
64 // -- but it also says "If changes to the iterated list do not
65 // remove the reference node, they do not affect the state
66 // of the NodeIterator."
68 expect(17, i.previousNode(), t1); // filter 8
71 document.body.removeChild(iframe);
73 var successfullyParsed = true;