1 description('Test TreeWalker with rejection'); 2 3 var walker; 4 var testElement = document.createElement("div"); 5 testElement.innerHTML='<div id="A1"> <div id="B1"> <div id="C1"></div> </div> <div id="B2"></div><div id="B3"></div> </div>'; 6 7 var rejectB1Filter = { 8 acceptNode: function(node) { 9 if (node.id == 'B1') 10 return NodeFilter.FILTER_REJECT; 11 12 return NodeFilter.FILTER_ACCEPT; 13 } 14 } 15 16 var rejectB2Filter = { 17 acceptNode: function(node) { 18 if (node.id == 'B2') 19 return NodeFilter.FILTER_SKIP; 20 21 return NodeFilter.FILTER_ACCEPT; 22 } 23 } 24 25 debug("<br>Testing nextNode") 26 walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, rejectB1Filter, false); 27 shouldBe("walker.nextNode(); walker.currentNode.id", "'A1'"); 28 shouldBe("walker.nextNode(); walker.currentNode.id", "'B2'"); 29 shouldBe("walker.nextNode(); walker.currentNode.id", "'B3'"); 30 31 debug("<br>Testing firstChild") 32 walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, rejectB1Filter, false); 33 shouldBe("walker.firstChild(); walker.currentNode.id", "'A1'"); 34 shouldBe("walker.firstChild(); walker.currentNode.id", "'B2'"); 35 36 debug("<br>Testing nextSibling") 37 walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, rejectB2Filter, false); 38 shouldBe("walker.firstChild(); walker.currentNode.id", "'A1'"); 39 shouldBe("walker.firstChild(); walker.currentNode.id", "'B1'"); 40 shouldBe("walker.nextSibling(); walker.currentNode.id", "'B3'"); 41 42 debug("<br>Testing parentNode") 43 walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, rejectB1Filter, false); 44 walker.currentNode = testElement.querySelectorAll('#C1')[0]; 45 shouldBe("walker.parentNode(); walker.currentNode.id", "'A1'"); 46 47 debug("<br>Testing previousSibling") 48 walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, rejectB2Filter, false); 49 walker.currentNode = testElement.querySelectorAll('#B3')[0]; 50 shouldBe("walker.previousSibling(); walker.currentNode.id", "'B1'"); 51 52 debug("<br>Testing previousNode") 53 walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, rejectB1Filter, false); 54 walker.currentNode = testElement.querySelectorAll('#B3')[0]; 55 shouldBe("walker.previousNode(); walker.currentNode.id", "'B2'"); 56 shouldBe("walker.previousNode(); walker.currentNode.id", "'A1'"); 57 58 var successfullyParsed = true; 59