Tizen 2.1 base
[framework/web/webkit-efl.git] / LayoutTests / traversal / tree-walker-filter-1.html
1 <script>
2 function doLog(msg)
3 {
4     var d = document.createElement("div");
5     d.innerHTML = msg;
6     document.body.appendChild(d);
7 }
8
9 function report(msg, res)
10 {
11     if (res)
12         msg = "<font color=green>PASS:</font>" + msg;
13     else
14         msg = "<font color=red>FAIL:</font>" + msg;
15     doLog(msg);
16 }
17
18 /*
19  Tree:
20     a
21         b
22             c
23         d
24             e
25         f
26         g
27             h
28    b, c are rejected,
29    d is skipped.
30    g is rejected
31 */
32 function kid(parent) {
33     var newKid = document.createElement("div");
34     parent.appendChild(newKid);
35     return newKid;
36 }
37
38 function test() {
39     if (window.testRunner)
40         testRunner.dumpAsText();
41
42     var wrapper = document.createElement("div"); // just to have one more level up.
43
44     var a = kid(wrapper);
45         var b = kid(a);
46             var c = kid(b);
47         var d = kid(a);
48             var e = kid(d);
49         var f = kid(a);
50         var g = kid(a);
51             var h = kid(g);
52     a.setAttribute("id", "a");
53     b.setAttribute("id", "b");
54     c.setAttribute("id", "c");
55     d.setAttribute("id", "d");
56     e.setAttribute("id", "e");
57     f.setAttribute("id", "f");
58     g.setAttribute("id", "g");
59     h.setAttribute("id", "h");
60
61     function filter(node) {
62         if (node == b || node == c || node == g)
63             return NodeFilter.FILTER_REJECT;
64         if (node == d)
65             return NodeFilter.FILTER_SKIP;
66         return NodeFilter.FILTER_ACCEPT;
67     }
68     
69     var tw = document.createTreeWalker(a, NodeFilter.SHOW_ALL, filter, true);
70     report("Proper a.firstChild()", tw.firstChild() == e);
71
72     tw.currentNode = b;
73     report("Proper b.firstChild()", tw.firstChild() == null);
74     // shouldn't move.
75     report("Shouldn't move", tw.currentNode == b);
76
77     tw.currentNode = b;
78     report("Proper b.nextSibling()", tw.nextSibling() == e);
79
80     // This is because we should treat 'b' as skipped when we are under it.
81     tw.currentNode = c;
82     report("Proper c.nextSibling()", tw.nextSibling() == e);
83
84     tw.currentNode = e;
85     report("Proper e.nextSibling()", tw.nextSibling() == f);
86
87     tw.currentNode = f;
88     report("Proper f.previousSibling()", tw.previousSibling() == e);
89     tw.currentNode = e;
90     report("Proper e.previousSibling()", tw.previousSibling() == null);
91     report("Shouldn't move", tw.currentNode == e);
92
93     tw.currentNode = h;
94     report("Proper h.previousSibling()", tw.previousSibling() == f);
95
96     tw.currentNode = g;
97     report("Proper g.previousSibling()", tw.previousSibling() == f);
98     // f is g's previous sibling, but not the other way around :-)
99     tw.currentNode = f;
100     report("Proper f.nextSibling()", tw.nextSibling() == null);
101     report("Proper f.parentNode()", tw.parentNode() == a);
102     report("Proper a.parentNode()", tw.parentNode() == null);
103
104     // Test exit/capture.
105     tw.currentNode = a.parentNode;
106     report("Proper a's parent.nextNode()", tw.nextNode() == a);
107     // Should get caught..
108     report("Re-capture #1", tw.previousNode() == null);
109     report("Re-capture #2", tw.parentNode() == null);
110     report("nextNode from a", tw.nextNode() == e);
111     report("prevNode to a", tw.previousNode() == a);
112
113     doLog("All done!");
114 }
115
116 </script>
117 <body onload="test()">