1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug628938.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,239 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=628938 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 628938</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=628938">Mozilla Bug 628938</a> 1.16 +<p id="display"></p> 1.17 +<foo id="content" style="display: none"> 1.18 + <div><div>foo</div></div> 1.19 + <span> bar </span> 1.20 + <div>tulip<span>bar</span></div> 1.21 + <span></span> 1.22 + <div>foo</div> 1.23 + <span></span> 1.24 + <div>bar</div> 1.25 + <span></span> 1.26 + <div>foobar</div> 1.27 +</foo> 1.28 +<pre id="test"> 1.29 +<script type="application/javascript"> 1.30 + 1.31 +/** Test for Bug 628938 **/ 1.32 + 1.33 +var gResults = []; 1.34 +var gIdx = 0; 1.35 + 1.36 +function walkTree(walker) 1.37 +{ 1.38 + if(walker.firstChild()) { 1.39 + do { 1.40 + if (walker.currentNode.nodeType == Node.ELEMENT_NODE) { 1.41 + ok(gResults[gIdx][0], "current node should be an element"); 1.42 + is(walker.currentNode.nodeName, gResults[gIdx][1], 1.43 + "current node name should be " + gResults[gIdx][1]); 1.44 + } else { 1.45 + ok(!gResults[gIdx][0], "current node shouldn't be an element"); 1.46 + is(walker.currentNode.nodeValue, gResults[gIdx][1], 1.47 + "current node value should be " + gResults[gIdx][1]); 1.48 + } 1.49 + gIdx++; 1.50 + // Recursively walk the rest of the sub-tree. 1.51 + walkTree(walker); 1.52 + } while(walker.nextSibling()); 1.53 + 1.54 + // don't forget to return the treewalker to it's previous state 1.55 + // before exiting the function 1.56 + walker.parentNode(); 1.57 + } 1.58 +} 1.59 + 1.60 +function regularWalk() 1.61 +{ 1.62 + gResults = [ 1.63 + [ false, "\n " ], 1.64 + [ true, "DIV" ], 1.65 + [ true, "DIV" ], 1.66 + [ false, "foo" ], 1.67 + [ false, "\n " ], 1.68 + [ true, "SPAN" ], 1.69 + [ false, " bar " ], 1.70 + [ false, "\n " ], 1.71 + [ true, "DIV" ], 1.72 + [ false, "tulip" ], 1.73 + [ true, "SPAN" ], 1.74 + [ false, "bar" ], 1.75 + [ false, "\n " ], 1.76 + [ true, "SPAN" ], 1.77 + [ false, "\n " ], 1.78 + [ true, "DIV" ], 1.79 + [ false, "foo" ], 1.80 + [ false, "\n " ], 1.81 + [ true, "SPAN" ], 1.82 + [ false, "\n " ], 1.83 + [ true, "DIV" ], 1.84 + [ false, "bar" ], 1.85 + [ false, "\n " ], 1.86 + [ true, "SPAN" ], 1.87 + [ false, "\n " ], 1.88 + [ true, "DIV" ], 1.89 + [ false, "foobar" ], 1.90 + [ false, "\n" ], 1.91 + ]; 1.92 + var walker = document.createTreeWalker(document.getElementById('content'), 1.93 + NodeFilter.SHOW_ALL, null); 1.94 + 1.95 + walkTree(walker); 1.96 + 1.97 + gIdx = 0; 1.98 +} 1.99 + 1.100 +function noWhiteSpaceWalk() 1.101 +{ 1.102 + gResults = [ 1.103 + [ true, "DIV" ], 1.104 + [ true, "DIV" ], 1.105 + [ false, "foo" ], 1.106 + [ true, "SPAN" ], 1.107 + [ false, " bar " ], 1.108 + [ true, "DIV" ], 1.109 + [ false, "tulip" ], 1.110 + [ true, "SPAN" ], 1.111 + [ false, "bar" ], 1.112 + [ true, "SPAN" ], 1.113 + [ true, "DIV" ], 1.114 + [ false, "foo" ], 1.115 + [ true, "SPAN" ], 1.116 + [ true, "DIV" ], 1.117 + [ false, "bar" ], 1.118 + [ true, "SPAN" ], 1.119 + [ true, "DIV" ], 1.120 + [ false, "foobar" ], 1.121 + ]; 1.122 + var walker = document.createTreeWalker(document.getElementById('content'), 1.123 + NodeFilter.SHOW_ALL, 1.124 + { 1.125 + acceptNode : function(node) { 1.126 + if (node.nodeType == Node.TEXT_NODE && 1.127 + !(/[^\t\n\r ]/.test(node.nodeValue))) 1.128 + return NodeFilter.FILTER_REJECT; 1.129 + return NodeFilter.FILTER_ACCEPT; 1.130 + } 1.131 + }); 1.132 + 1.133 + walkTree(walker); 1.134 + 1.135 + gIdx = 0; 1.136 +} 1.137 + 1.138 +function onlyElementsWalk() 1.139 +{ 1.140 + gResults = [ 1.141 + [ true, "DIV" ], 1.142 + [ true, "DIV" ], 1.143 + [ true, "SPAN" ], 1.144 + [ true, "DIV" ], 1.145 + [ true, "SPAN" ], 1.146 + [ true, "SPAN" ], 1.147 + [ true, "DIV" ], 1.148 + [ true, "SPAN" ], 1.149 + [ true, "DIV" ], 1.150 + [ true, "SPAN" ], 1.151 + [ true, "DIV" ], 1.152 + ]; 1.153 + var walker = document.createTreeWalker(document.getElementById('content'), 1.154 + NodeFilter.SHOW_ELEMENT, null); 1.155 + 1.156 + walkTree(walker); 1.157 + 1.158 + gIdx = 0; 1.159 +} 1.160 + 1.161 +function onlyDivSubTreeWalk() 1.162 +{ 1.163 + gResults = [ 1.164 + [ true, "DIV" ], 1.165 + [ true, "DIV" ], 1.166 + [ false, "foo" ], 1.167 + [ true, "DIV" ], 1.168 + [ false, "tulip" ], 1.169 + [ true, "SPAN" ], 1.170 + [ false, "bar" ], 1.171 + [ true, "DIV" ], 1.172 + [ false, "foo" ], 1.173 + [ true, "DIV" ], 1.174 + [ false, "bar" ], 1.175 + [ true, "DIV" ], 1.176 + [ false, "foobar" ], 1.177 + ]; 1.178 + var walker = document.createTreeWalker(document.getElementById('content'), 1.179 + NodeFilter.SHOW_ALL, 1.180 + { 1.181 + acceptNode : function(node) { 1.182 + if (node.nodeType == Node.TEXT_NODE && 1.183 + !(/[^\t\n\r ]/.test(node.nodeValue))) 1.184 + return NodeFilter.FILTER_REJECT; 1.185 + 1.186 + while (node) { 1.187 + if (node.nodeName == "DIV") 1.188 + return NodeFilter.FILTER_ACCEPT; 1.189 + node = node.parentNode; 1.190 + } 1.191 + return NodeFilter.FILTER_SKIP; 1.192 + } 1.193 + }); 1.194 + 1.195 + walkTree(walker); 1.196 + 1.197 + gIdx = 0; 1.198 +} 1.199 + 1.200 +function onlyDivDataWalk() 1.201 +{ 1.202 + gResults = [ 1.203 + [ true, "DIV" ], 1.204 + [ true, "DIV" ], 1.205 + [ false, "foo" ], 1.206 + [ true, "DIV" ], 1.207 + [ false, "tulip" ], 1.208 + [ true, "SPAN" ], 1.209 + [ true, "DIV" ], 1.210 + [ false, "foo" ], 1.211 + [ true, "DIV" ], 1.212 + [ false, "bar" ], 1.213 + [ true, "DIV" ], 1.214 + [ false, "foobar" ], 1.215 + ]; 1.216 + var walker = document.createTreeWalker(document.getElementById('content'), 1.217 + NodeFilter.SHOW_ALL, 1.218 + { 1.219 + acceptNode : function(node) { 1.220 + if (node.nodeName == "DIV" || 1.221 + (node.parentNode && 1.222 + node.parentNode.nodeName == "DIV")) 1.223 + return NodeFilter.FILTER_ACCEPT; 1.224 + return NodeFilter.FILTER_SKIP; 1.225 + } 1.226 + }); 1.227 + 1.228 + walkTree(walker); 1.229 + 1.230 + gIdx = 0; 1.231 +} 1.232 + 1.233 +regularWalk(); 1.234 +noWhiteSpaceWalk(); 1.235 +onlyElementsWalk(); 1.236 +onlyDivSubTreeWalk(); 1.237 +onlyDivDataWalk(); 1.238 + 1.239 +</script> 1.240 +</pre> 1.241 +</body> 1.242 +</html>