• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1description("Tests the TreeWalker.")
2
3var subTree = document.createElement('div');
4subTree.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>"
5document.body.appendChild(subTree);
6
7var all = function(node) { return true; }
8var w = document.createTreeWalker(subTree, 0x01 | 0x08 | 0x10 | 0x20, all, true);
9
10debug("Test that TreeWalker.parent() doesn't set the currentNode to a node not under the root.");
11debug("");
12
13shouldBe("w.currentNode", "subTree");
14shouldBeNull("w.parentNode()");
15shouldBe("w.currentNode", "subTree");
16
17debug("");
18debug("Test that we handle setting the currentNode to arbitrary nodes not under the root element.");
19debug("");
20
21w.currentNode = document.documentElement;
22shouldBeNull("w.parentNode()");
23shouldBe("w.currentNode", "document.documentElement");
24w.currentNode = document.documentElement;
25shouldBe("w.nextNode()", "document.documentElement.firstChild");
26shouldBe("w.currentNode", "document.documentElement.firstChild");
27w.currentNode = document.documentElement;
28shouldBeNull("w.previousNode()");
29shouldBe("w.currentNode", "document.documentElement");
30w.currentNode = document.documentElement;
31shouldBe("w.firstChild()", "document.documentElement.firstChild");
32shouldBe("w.currentNode", "document.documentElement.firstChild");
33w.currentNode = document.documentElement;
34shouldBe("w.lastChild()", "document.documentElement.lastChild");
35shouldBe("w.currentNode", "document.documentElement.lastChild");
36w.currentNode = document.documentElement;
37shouldBeNull("w.nextSibling()");
38shouldBe("w.currentNode", "document.documentElement");
39w.currentNode = document.documentElement;
40shouldBeNull("w.previousSibling()");
41shouldBe("w.currentNode", "document.documentElement");
42
43debug("");
44debug("Test how we handle the case when the traversed to node within the root, but the currentElement is not.");
45debug("");
46
47w.currentNode = subTree.previousSibling;
48shouldBe("w.nextNode()", "subTree");
49w.currentNode = document.body;
50shouldBe("w.lastChild()", "subTree");
51
52// Cleanup
53document.body.removeChild(subTree);
54
55var successfullyParsed = true;
56