|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <!-- |
|
3 https://bugzilla.mozilla.org/show_bug.cgi?id=522601 |
|
4 --> |
|
5 <head> |
|
6 <title>Test for Bug 522601</title> |
|
7 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
9 |
|
10 <bindings xmlns="http://www.mozilla.org/xbl"> |
|
11 <binding id="testBinding"> |
|
12 <content><div><children/></div><children includes="span"/></content> |
|
13 </binding> |
|
14 </bindings> |
|
15 </head> |
|
16 <body> |
|
17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=522601">Mozilla Bug 522601</a> |
|
18 <p id="display" style="-moz-binding: url(#testBinding)"> |
|
19 <span id="s">This is some text</span> |
|
20 More text |
|
21 <b id="b">Even more <i id="i1">Italic</i>text<i id="i2">And more italic</i></b></p> |
|
22 <div id="content" style="display: none"> |
|
23 |
|
24 </div> |
|
25 <pre id="test"> |
|
26 <script type="application/javascript"> |
|
27 <![CDATA[ |
|
28 |
|
29 /** Test for Bug 522601 **/ |
|
30 SimpleTest.waitForExplicitFinish(); |
|
31 |
|
32 function testFunc(walker, func, expectedNode, str) { |
|
33 var oldCurrent = SpecialPowers.unwrap(walker.currentNode); |
|
34 var newNode = SpecialPowers.unwrap(walker[func]()); |
|
35 is(newNode, expectedNode, "Unexpected node after " + str); |
|
36 is(SpecialPowers.unwrap(walker.currentNode), newNode ? newNode : oldCurrent, |
|
37 "Unexpected current node after " + str); |
|
38 } |
|
39 |
|
40 addLoadEvent(function() { |
|
41 var walkerNonAnon = |
|
42 SpecialPowers.Cc["@mozilla.org/inspector/deep-tree-walker;1"] |
|
43 .createInstance(SpecialPowers.Ci.inIDeepTreeWalker); |
|
44 walkerNonAnon.init($("display"), NodeFilter.SHOW_ALL); |
|
45 walkerNonAnon.showAnonymousContent = false; |
|
46 |
|
47 is(SpecialPowers.unwrap(walkerNonAnon.currentNode), $("display"), "Unexpected non-anon root"); |
|
48 testFunc(walkerNonAnon, "nextNode", $("s").previousSibling, |
|
49 "step to some text"); |
|
50 testFunc(walkerNonAnon, "nextNode", $("s"), "step to span"); |
|
51 testFunc(walkerNonAnon, "nextNode", $("s").firstChild, "step to span text"); |
|
52 testFunc(walkerNonAnon, "nextNode", $("s").nextSibling, "step to more text"); |
|
53 testFunc(walkerNonAnon, "nextNode", $("b"), "step to bold"); |
|
54 testFunc(walkerNonAnon, "nextNode", $("b").firstChild, "step to bold text"); |
|
55 testFunc(walkerNonAnon, "nextNode", $("i1"), "step to first italic"); |
|
56 testFunc(walkerNonAnon, "nextNode", $("i1").firstChild, |
|
57 "step to first italic text"); |
|
58 testFunc(walkerNonAnon, "nextNode", $("i1").nextSibling, |
|
59 "step to more bold text"); |
|
60 testFunc(walkerNonAnon, "nextNode", $("i2"), "step to second italic"); |
|
61 testFunc(walkerNonAnon, "nextNode", $("i2").firstChild, |
|
62 "step to second italic text"); |
|
63 testFunc(walkerNonAnon, "nextNode", null, "step past end"); |
|
64 testFunc(walkerNonAnon, "parentNode", $("i2"), "step up to second italic"); |
|
65 testFunc(walkerNonAnon, "parentNode", $("b"), "step up to bold"); |
|
66 testFunc(walkerNonAnon, "nextNode", $("b").firstChild, "step to bold text again"); |
|
67 testFunc(walkerNonAnon, "parentNode", $("b"), "step up to bold again"); |
|
68 testFunc(walkerNonAnon, "parentNode", $("display"), "step up to display"); |
|
69 testFunc(walkerNonAnon, "parentNode", null, "step up past root"); |
|
70 testFunc(walkerNonAnon, "firstChild", $("s").previousSibling, |
|
71 "step firstChild to display first child"); |
|
72 testFunc(walkerNonAnon, "nextSibling", $("s"), |
|
73 "step nextSibling to span"); |
|
74 testFunc(walkerNonAnon, "nextSibling", $("s").nextSibling, |
|
75 "step nextSibling to more text"); |
|
76 testFunc(walkerNonAnon, "nextSibling", $("b"), "step nextSibling to bold"); |
|
77 testFunc(walkerNonAnon, "nextSibling", null, "step nextSibling past end"); |
|
78 testFunc(walkerNonAnon, "previousSibling", $("s").nextSibling, |
|
79 "step previousSibling to more text"); |
|
80 testFunc(walkerNonAnon, "previousSibling", $("s"), |
|
81 "step previousSibling to span"); |
|
82 testFunc(walkerNonAnon, "previousSibling", $("s").previousSibling, |
|
83 "step previousSibling to display first child"); |
|
84 testFunc(walkerNonAnon, "previousSibling", null, |
|
85 "step previousSibling past end"); |
|
86 |
|
87 // Move the walker over to the end |
|
88 while (walkerNonAnon.nextNode()) { /* do nothing */ } |
|
89 is(SpecialPowers.unwrap(walkerNonAnon.currentNode), $("i2").firstChild, "unexpected last node"); |
|
90 testFunc(walkerNonAnon, "previousNode", $("i2"), "step back to second italic"); |
|
91 testFunc(walkerNonAnon, "previousNode", $("i1").nextSibling, |
|
92 "step back to more bold text"); |
|
93 testFunc(walkerNonAnon, "previousNode", $("i1").firstChild, |
|
94 "step back to first italic text"); |
|
95 testFunc(walkerNonAnon, "previousNode", $("i1"), "step back to first italic"); |
|
96 testFunc(walkerNonAnon, "previousNode", $("b").firstChild, |
|
97 "step back to bold text"); |
|
98 testFunc(walkerNonAnon, "previousNode", $("b"), "step back to bold"); |
|
99 testFunc(walkerNonAnon, "previousNode", $("s").nextSibling, "step back to more text"); |
|
100 testFunc(walkerNonAnon, "previousNode", $("s").firstChild, "step back to span text"); |
|
101 testFunc(walkerNonAnon, "previousNode", $("s"), "step back to span"); |
|
102 testFunc(walkerNonAnon, "previousNode", $("s").previousSibling, |
|
103 "step back to some text"); |
|
104 testFunc(walkerNonAnon, "previousNode", $("display"), |
|
105 "step back to root"); |
|
106 testFunc(walkerNonAnon, "previousNode", null, |
|
107 "step back past root"); |
|
108 |
|
109 var anonDiv = SpecialPowers.unwrap(SpecialPowers.wrap(document).getAnonymousNodes($("display")))[0]; |
|
110 |
|
111 var walkerAnon = |
|
112 SpecialPowers.Cc["@mozilla.org/inspector/deep-tree-walker;1"] |
|
113 .createInstance(SpecialPowers.Ci.inIDeepTreeWalker); |
|
114 walkerAnon.showAnonymousContent = true; |
|
115 walkerAnon.init($("display"), NodeFilter.SHOW_ALL); |
|
116 |
|
117 is(SpecialPowers.unwrap(walkerAnon.currentNode), $("display"), "Unexpected anon root"); |
|
118 testFunc(walkerAnon, "nextNode", anonDiv, |
|
119 "step to anonymous div"); |
|
120 testFunc(walkerAnon, "nextNode", $("s").previousSibling, |
|
121 "step to some text (anon)"); |
|
122 testFunc(walkerAnon, "nextNode", $("s").nextSibling, "step to more text (anon)"); |
|
123 testFunc(walkerAnon, "nextNode", $("b"), "step to bold (anon)"); |
|
124 testFunc(walkerAnon, "nextNode", $("b").firstChild, "step to bold text (anon)"); |
|
125 testFunc(walkerAnon, "nextNode", $("i1"), "step to first italic (anon)"); |
|
126 testFunc(walkerAnon, "nextNode", $("i1").firstChild, |
|
127 "step to first italic text (anon)"); |
|
128 testFunc(walkerAnon, "nextNode", $("i1").nextSibling, |
|
129 "step to more bold text (anon)"); |
|
130 testFunc(walkerAnon, "nextNode", $("i2"), "step to second italic (anon)"); |
|
131 testFunc(walkerAnon, "nextNode", $("i2").firstChild, |
|
132 "step to second italic text (anon)"); |
|
133 testFunc(walkerAnon, "nextNode", $("s"), "step to span (anon)"); |
|
134 testFunc(walkerAnon, "nextNode", $("s").firstChild, "step to span text (anon)"); |
|
135 testFunc(walkerAnon, "nextNode", null, "step past end (anon)"); |
|
136 testFunc(walkerAnon, "parentNode", $("s"), "step up to span (anon)"); |
|
137 testFunc(walkerAnon, "parentNode", $("display"), "step up to display (anon)"); |
|
138 testFunc(walkerAnon, "nextNode", anonDiv, "step to anonymous div again"); |
|
139 testFunc(walkerAnon, "parentNode", $("display"), |
|
140 "step up to display again (anon)"); |
|
141 testFunc(walkerAnon, "parentNode", null, "step up past root (anon)"); |
|
142 testFunc(walkerAnon, "firstChild", anonDiv, |
|
143 "step firstChild to display first child (anon)"); |
|
144 testFunc(walkerAnon, "nextSibling", $("s"), |
|
145 "step nextSibling to span (anon)"); |
|
146 testFunc(walkerAnon, "nextSibling", null, "step nextSibling past end (anon)"); |
|
147 testFunc(walkerAnon, "previousSibling", anonDiv, |
|
148 "step previousSibling to anonymous div"); |
|
149 testFunc(walkerAnon, "previousSibling", null, "step previousSibling past end (anon)"); |
|
150 |
|
151 // Move the walker over to the end |
|
152 while (walkerAnon.nextNode()) { /* do nothing */ } |
|
153 testFunc(walkerAnon, "previousNode", $("s"), "step back to span (anon)"); |
|
154 testFunc(walkerAnon, "previousNode", $("i2").firstChild, |
|
155 "step back to second italic text (anon)"); |
|
156 testFunc(walkerAnon, "previousNode", $("i2"), "step back to second italic (anon)"); |
|
157 testFunc(walkerAnon, "previousNode", $("i1").nextSibling, |
|
158 "step back to more bold text (anon)"); |
|
159 testFunc(walkerAnon, "previousNode", $("i1").firstChild, |
|
160 "step back to first italic text (anon)"); |
|
161 testFunc(walkerAnon, "previousNode", $("i1"), "step back to first italic (anon)"); |
|
162 testFunc(walkerAnon, "previousNode", $("b").firstChild, "step back to bold text (anon)"); |
|
163 testFunc(walkerAnon, "previousNode", $("b"), "step back to bold (anon)"); |
|
164 testFunc(walkerAnon, "previousNode", $("s").nextSibling, "step back to more text (anon)"); |
|
165 testFunc(walkerAnon, "previousNode", $("s").previousSibling, |
|
166 "step back to some text (anon)"); |
|
167 testFunc(walkerAnon, "previousNode", anonDiv, |
|
168 "step back to anonymous div"); |
|
169 testFunc(walkerAnon, "previousNode", $("display"), "step back to root (anon)"); |
|
170 testFunc(walkerAnon, "previousNode", null, "step back past root (anon)"); |
|
171 |
|
172 SimpleTest.finish(); |
|
173 }); |
|
174 |
|
175 ]]> |
|
176 </script> |
|
177 </pre> |
|
178 </body> |
|
179 </html> |