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