4 var d = document.createElement("div");
6 document.body.appendChild(d);
9 function report(msg, res)
12 msg = "<font color=green>PASS:</font>" + msg;
14 msg = "<font color=red>FAIL:</font>" + msg;
32 function kid(parent) {
33 var newKid = document.createElement("div");
34 parent.appendChild(newKid);
39 if (window.testRunner)
40 testRunner.dumpAsText();
42 var wrapper = document.createElement("div"); // just to have one more level up.
52 a.setAttribute("id", "a");
53 b.setAttribute("id", "b");
54 c.setAttribute("id", "c");
55 d.setAttribute("id", "d");
56 e.setAttribute("id", "e");
57 f.setAttribute("id", "f");
58 g.setAttribute("id", "g");
59 h.setAttribute("id", "h");
61 function filter(node) {
62 if (node == b || node == c || node == g)
63 return NodeFilter.FILTER_REJECT;
65 return NodeFilter.FILTER_SKIP;
66 return NodeFilter.FILTER_ACCEPT;
69 var tw = document.createTreeWalker(a, NodeFilter.SHOW_ALL, filter, true);
70 report("Proper a.firstChild()", tw.firstChild() == e);
73 report("Proper b.firstChild()", tw.firstChild() == null);
75 report("Shouldn't move", tw.currentNode == b);
78 report("Proper b.nextSibling()", tw.nextSibling() == e);
80 // This is because we should treat 'b' as skipped when we are under it.
82 report("Proper c.nextSibling()", tw.nextSibling() == e);
85 report("Proper e.nextSibling()", tw.nextSibling() == f);
88 report("Proper f.previousSibling()", tw.previousSibling() == e);
90 report("Proper e.previousSibling()", tw.previousSibling() == null);
91 report("Shouldn't move", tw.currentNode == e);
94 report("Proper h.previousSibling()", tw.previousSibling() == f);
97 report("Proper g.previousSibling()", tw.previousSibling() == f);
98 // f is g's previous sibling, but not the other way around :-)
100 report("Proper f.nextSibling()", tw.nextSibling() == null);
101 report("Proper f.parentNode()", tw.parentNode() == a);
102 report("Proper a.parentNode()", tw.parentNode() == null);
104 // Test exit/capture.
105 tw.currentNode = a.parentNode;
106 report("Proper a's parent.nextNode()", tw.nextNode() == a);
107 // Should get caught..
108 report("Re-capture #1", tw.previousNode() == null);
109 report("Re-capture #2", tw.parentNode() == null);
110 report("nextNode from a", tw.nextNode() == e);
111 report("prevNode to a", tw.previousNode() == a);
117 <body onload="test()">