1 description("Tests the TreeWalker.") 2 3 var subTree = document.createElement('div'); 4 subTree.innerHTML = "<p>Lorem ipsum <span>dolor <b>sit</b> amet</span>, consectetur <i>adipisicing</i> elit, sed do eiusmod <tt>tempor <b><i>incididunt ut</i> labore</b> et dolore magna</tt> aliqua.</p>" 5 document.body.appendChild(subTree); 6 7 var all = function(node) { return true; } 8 var w = document.createTreeWalker(subTree, 0x01 | 0x08 | 0x10 | 0x20, all, true); 9 10 debug("Test that TreeWalker.parent() doesn't set the currentNode to a node not under the root."); 11 debug(""); 12 13 shouldBe("w.currentNode", "subTree"); 14 shouldBeNull("w.parentNode()"); 15 shouldBe("w.currentNode", "subTree"); 16 17 debug(""); 18 debug("Test that we handle setting the currentNode to arbitrary nodes not under the root element."); 19 debug(""); 20 21 w.currentNode = document.documentElement; 22 shouldBeNull("w.parentNode()"); 23 shouldBe("w.currentNode", "document.documentElement"); 24 w.currentNode = document.documentElement; 25 shouldBe("w.nextNode()", "document.documentElement.firstChild"); 26 shouldBe("w.currentNode", "document.documentElement.firstChild"); 27 w.currentNode = document.documentElement; 28 shouldBeNull("w.previousNode()"); 29 shouldBe("w.currentNode", "document.documentElement"); 30 w.currentNode = document.documentElement; 31 shouldBe("w.firstChild()", "document.documentElement.firstChild"); 32 shouldBe("w.currentNode", "document.documentElement.firstChild"); 33 w.currentNode = document.documentElement; 34 shouldBe("w.lastChild()", "document.documentElement.lastChild"); 35 shouldBe("w.currentNode", "document.documentElement.lastChild"); 36 w.currentNode = document.documentElement; 37 shouldBeNull("w.nextSibling()"); 38 shouldBe("w.currentNode", "document.documentElement"); 39 w.currentNode = document.documentElement; 40 shouldBeNull("w.previousSibling()"); 41 shouldBe("w.currentNode", "document.documentElement"); 42 43 debug(""); 44 debug("Test how we handle the case when the traversed to node within the root, but the currentElement is not."); 45 debug(""); 46 47 w.currentNode = subTree.previousSibling; 48 shouldBe("w.nextNode()", "subTree"); 49 w.currentNode = document.body; 50 shouldBe("w.lastChild()", "subTree"); 51 52 // Cleanup 53 document.body.removeChild(subTree); 54 55 var successfullyParsed = true; 56