|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=559526 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 559526</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=559526">Mozilla Bug 559526</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <div id="nodes" style="display:none"> |
|
19 <div id="child1"></div> |
|
20 <div id="child2"></div> |
|
21 |
|
22 <div id="child3"></div> |
|
23 <div id="child4"></div> |
|
24 <div id="child5"></div> |
|
25 <div id="child6"></div> |
|
26 <div id="child7"></div> |
|
27 <div id="child8"></div> |
|
28 </div> |
|
29 <script type="application/javascript"> |
|
30 |
|
31 /** Test for Bug 559526 **/ |
|
32 |
|
33 var it; |
|
34 var recurse = false; |
|
35 var testCount = 0; |
|
36 function filter(node) { |
|
37 if (node.id == "child3" && ! recurse) { |
|
38 recurse = true; |
|
39 var ex = null; |
|
40 try { |
|
41 var foo = it.nextNode(); |
|
42 } catch(e) { |
|
43 ex = e; |
|
44 } |
|
45 ++testCount; |
|
46 is(ex.name, "InvalidStateError", "Should have thrown an exception!"); |
|
47 is(ex.code, DOMException.INVALID_STATE_ERR, "Should have thrown an exception!"); |
|
48 recurse = false; |
|
49 } |
|
50 return NodeFilter.FILTER_ACCEPT; |
|
51 } |
|
52 |
|
53 (function testNodeIterator() { |
|
54 |
|
55 it = document.createNodeIterator( |
|
56 document.getElementById("nodes"), |
|
57 NodeFilter.SHOW_ELEMENT, |
|
58 filter |
|
59 ); |
|
60 while (it.nextNode()); |
|
61 })(); |
|
62 |
|
63 (function testTreeWalker() { |
|
64 it = document.createTreeWalker( |
|
65 document.getElementById("nodes"), |
|
66 NodeFilter.SHOW_ELEMENT, |
|
67 filter |
|
68 ); |
|
69 while(it.nextNode()); |
|
70 |
|
71 it = document.createTreeWalker( |
|
72 document.getElementById("nodes"), |
|
73 NodeFilter.SHOW_ELEMENT, |
|
74 filter |
|
75 ); |
|
76 it.firstChild(); |
|
77 while(it.nextSibling()); |
|
78 |
|
79 it = document.createTreeWalker( |
|
80 document.getElementById("nodes"), |
|
81 NodeFilter.SHOW_ELEMENT, |
|
82 filter |
|
83 ); |
|
84 it.lastChild(); |
|
85 while(it.previousSibling()); |
|
86 })(); |
|
87 |
|
88 is(testCount, 4, "Should have tests 3 filter calls!"); |
|
89 |
|
90 </script> |
|
91 </pre> |
|
92 </body> |
|
93 </html> |