OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <!-- |
| 4 Test adapted from https://mxr.mozilla.org/chromium/source/src/third_party/WebKit
/LayoutTests/fast/dom/TreeWalker/script-tests/previousSiblingLastChildSkip.js |
| 5 --> |
| 6 <head> |
| 7 <title>TreeWalker: previousSiblingLastChildSkip</title> |
| 8 <script src="../../../../resources/testharness.js"></script> |
| 9 <script src="../../../../resources/testharnessreport.js"></script> |
| 10 <script src="traversal-support.js"></script> |
| 11 <link rel="stylesheet" href="../../../../resources/testharness.css"> |
| 12 <div id=log></div> |
| 13 </head> |
| 14 <body> |
| 15 <p>Test that previousSibling properly respects the filter.</p> |
| 16 <script> |
| 17 var testElement; |
| 18 setup(function() { |
| 19 testElement = document.createElement("div"); |
| 20 testElement.id = 'root'; |
| 21 // testElement.innerHTML='<div id="A1"><div id="B1"><div id="C1"></div><div
id="C2"><div id="D1"></div><div id="D2"></div></div></div><div id="B2"><div id="
C3"></div><div id="C4"></div></div></div>'; |
| 22 // testElement.innerHTML=' |
| 23 // <div id="A1"> |
| 24 // <div id="B1"> |
| 25 // <div id="C1"> |
| 26 // </div> |
| 27 // <div id="C2"> |
| 28 // <div id="D1"> |
| 29 // </div> |
| 30 // <div id="D2"> |
| 31 // </div> |
| 32 // </div> |
| 33 // </div> |
| 34 // <div id="B2"> |
| 35 // <div id="C3"> |
| 36 // </div> |
| 37 // <div id="C4"> |
| 38 // </div> |
| 39 // </div> |
| 40 // </div>'; |
| 41 |
| 42 // XXX for Servo, build the tree without using innerHTML |
| 43 var a1 = document.createElement("div"); a1.id = "A1"; |
| 44 var b1 = document.createElement("div"); b1.id = "B1"; |
| 45 var b2 = document.createElement("div"); b2.id = "B2"; |
| 46 var c1 = document.createElement("div"); c1.id = "C1"; |
| 47 var c2 = document.createElement("div"); c2.id = "C2"; |
| 48 var c3 = document.createElement("div"); c3.id = "C3"; |
| 49 var c4 = document.createElement("div"); c4.id = "C4"; |
| 50 var d1 = document.createElement("div"); d1.id = "D1"; |
| 51 var d2 = document.createElement("div"); d2.id = "D2"; |
| 52 |
| 53 testElement.appendChild(a1); |
| 54 a1.appendChild(b1); |
| 55 a1.appendChild(b2); |
| 56 b1.appendChild(c1); |
| 57 b1.appendChild(c2); |
| 58 b2.appendChild(c3); |
| 59 b2.appendChild(c4); |
| 60 c2.appendChild(d1); |
| 61 c2.appendChild(d2); |
| 62 }); |
| 63 |
| 64 test(function() |
| 65 { |
| 66 function filter(node) |
| 67 { |
| 68 if (node.id == "B1") |
| 69 return NodeFilter.FILTER_SKIP; |
| 70 return NodeFilter.FILTER_ACCEPT; |
| 71 } |
| 72 |
| 73 var walker = document.createTreeWalker(testElement, NodeFilter.SHOW_ELEMENT,
filter); |
| 74 assert_node(walker.currentNode, { type: Element, id: 'root' }); |
| 75 assert_node(walker.firstChild(), { type: Element, id: 'A1' }); |
| 76 assert_node(walker.currentNode, { type: Element, id: 'A1' }); |
| 77 assert_node(walker.nextNode(), { type: Element, id: 'C1' }); |
| 78 assert_node(walker.currentNode, { type: Element, id: 'C1' }); |
| 79 assert_node(walker.nextNode(), { type: Element, id: 'C2' }); |
| 80 assert_node(walker.currentNode, { type: Element, id: 'C2' }); |
| 81 assert_node(walker.nextNode(), { type: Element, id: 'D1' }); |
| 82 assert_node(walker.currentNode, { type: Element, id: 'D1' }); |
| 83 assert_node(walker.nextNode(), { type: Element, id: 'D2' }); |
| 84 assert_node(walker.currentNode, { type: Element, id: 'D2' }); |
| 85 assert_node(walker.nextNode(), { type: Element, id: 'B2' }); |
| 86 assert_node(walker.currentNode, { type: Element, id: 'B2' }); |
| 87 assert_node(walker.previousSibling(), { type: Element, id: 'C2' }); |
| 88 assert_node(walker.currentNode, { type: Element, id: 'C2' }); |
| 89 }, 'Test that previousSibling properly respects the filter.'); |
| 90 </script> |
| 91 </body> |
| 92 </html> |
OLD | NEW |