567ef665569e54436a89a40021391a82342ea511
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / dom / traversal / TreeWalker-traversal-skip-most.html
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Test adapted from https://dxr.mozilla.org/chromium/source/src/third_party/WebKit/LayoutTests/fast/dom/TreeWalker/script-tests/traversal-skip-most.js
5 -->
6 <head>
7 <title>TreeWalker: traversal-skip-most</title>
8 <script src="/resources/testharness.js"></script>
9 <script src="/resources/testharnessreport.js"></script>
10 <script src="traversal-support.js"></script>
11 <div id=log></div>
12 </head>
13 <body>
14 <p>Test TreeWalker with skipping</p>
15 <script>
16 var testElement;
17 setup(function() {
18     testElement = document.createElement("div");
19     testElement.id = 'root';
20     // testElement.innerHTML='<div id="A1"><div id="B1" class="keep"></div><div id="B2">this text matters</div><div id="B3" class="keep"></div></div>';
21     // <div id="A1">
22     //   <div id="B1" class="keep"></div>
23     //   <div id="B2">this text matters</div>
24     //   <div id="B3" class="keep"></div>
25     // </div>
26
27
28     // XXX for Servo, build the tree without using innerHTML
29     var a1 = document.createElement("div"); a1.id = "A1";
30     var b1 = document.createElement("div"); b1.id = "B1"; b1.className = "keep";
31     var b2 = document.createElement("div"); b2.id = "B2";
32     var b3 = document.createElement("div"); b3.id = "B3"; b3.className = "keep";
33
34     testElement.appendChild(a1);
35     a1.appendChild(b1);
36     a1.appendChild(b2)
37         .appendChild(document.createTextNode("this text matters"));
38     a1.appendChild(b3);
39 });
40
41 var filter = {
42   acceptNode: function(node) {
43     if (node.className == 'keep')
44       return NodeFilter.FILTER_ACCEPT;
45
46     return NodeFilter.FILTER_SKIP;
47   }
48 }
49
50 test(function()
51 {
52     var walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, filter);
53     assert_node(walker.firstChild(), { type: Element, id: 'B1' });
54     assert_node(walker.nextSibling(), { type: Element, id: 'B3' });
55 }, 'Testing nextSibling');
56
57 test(function()
58 {
59     var walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT, filter);
60     walker.currentNode = testElement.querySelectorAll('#B3')[0];
61     assert_node(walker.previousSibling(), { type: Element, id: 'B1' });
62 }, 'Testing previousSibling');
63
64 </script>
65 </body>
66 </html>