content/base/test/test_bug628938.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=628938
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 628938</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=628938">Mozilla Bug 628938</a>
michael@0 13 <p id="display"></p>
michael@0 14 <foo id="content" style="display: none">
michael@0 15 <div><div>foo</div></div>
michael@0 16 <span> bar </span>
michael@0 17 <div>tulip<span>bar</span></div>
michael@0 18 <span></span>
michael@0 19 <div>foo</div>
michael@0 20 <span></span>
michael@0 21 <div>bar</div>
michael@0 22 <span></span>
michael@0 23 <div>foobar</div>
michael@0 24 </foo>
michael@0 25 <pre id="test">
michael@0 26 <script type="application/javascript">
michael@0 27
michael@0 28 /** Test for Bug 628938 **/
michael@0 29
michael@0 30 var gResults = [];
michael@0 31 var gIdx = 0;
michael@0 32
michael@0 33 function walkTree(walker)
michael@0 34 {
michael@0 35 if(walker.firstChild()) {
michael@0 36 do {
michael@0 37 if (walker.currentNode.nodeType == Node.ELEMENT_NODE) {
michael@0 38 ok(gResults[gIdx][0], "current node should be an element");
michael@0 39 is(walker.currentNode.nodeName, gResults[gIdx][1],
michael@0 40 "current node name should be " + gResults[gIdx][1]);
michael@0 41 } else {
michael@0 42 ok(!gResults[gIdx][0], "current node shouldn't be an element");
michael@0 43 is(walker.currentNode.nodeValue, gResults[gIdx][1],
michael@0 44 "current node value should be " + gResults[gIdx][1]);
michael@0 45 }
michael@0 46 gIdx++;
michael@0 47 // Recursively walk the rest of the sub-tree.
michael@0 48 walkTree(walker);
michael@0 49 } while(walker.nextSibling());
michael@0 50
michael@0 51 // don't forget to return the treewalker to it's previous state
michael@0 52 // before exiting the function
michael@0 53 walker.parentNode();
michael@0 54 }
michael@0 55 }
michael@0 56
michael@0 57 function regularWalk()
michael@0 58 {
michael@0 59 gResults = [
michael@0 60 [ false, "\n " ],
michael@0 61 [ true, "DIV" ],
michael@0 62 [ true, "DIV" ],
michael@0 63 [ false, "foo" ],
michael@0 64 [ false, "\n " ],
michael@0 65 [ true, "SPAN" ],
michael@0 66 [ false, " bar " ],
michael@0 67 [ false, "\n " ],
michael@0 68 [ true, "DIV" ],
michael@0 69 [ false, "tulip" ],
michael@0 70 [ true, "SPAN" ],
michael@0 71 [ false, "bar" ],
michael@0 72 [ false, "\n " ],
michael@0 73 [ true, "SPAN" ],
michael@0 74 [ false, "\n " ],
michael@0 75 [ true, "DIV" ],
michael@0 76 [ false, "foo" ],
michael@0 77 [ false, "\n " ],
michael@0 78 [ true, "SPAN" ],
michael@0 79 [ false, "\n " ],
michael@0 80 [ true, "DIV" ],
michael@0 81 [ false, "bar" ],
michael@0 82 [ false, "\n " ],
michael@0 83 [ true, "SPAN" ],
michael@0 84 [ false, "\n " ],
michael@0 85 [ true, "DIV" ],
michael@0 86 [ false, "foobar" ],
michael@0 87 [ false, "\n" ],
michael@0 88 ];
michael@0 89 var walker = document.createTreeWalker(document.getElementById('content'),
michael@0 90 NodeFilter.SHOW_ALL, null);
michael@0 91
michael@0 92 walkTree(walker);
michael@0 93
michael@0 94 gIdx = 0;
michael@0 95 }
michael@0 96
michael@0 97 function noWhiteSpaceWalk()
michael@0 98 {
michael@0 99 gResults = [
michael@0 100 [ true, "DIV" ],
michael@0 101 [ true, "DIV" ],
michael@0 102 [ false, "foo" ],
michael@0 103 [ true, "SPAN" ],
michael@0 104 [ false, " bar " ],
michael@0 105 [ true, "DIV" ],
michael@0 106 [ false, "tulip" ],
michael@0 107 [ true, "SPAN" ],
michael@0 108 [ false, "bar" ],
michael@0 109 [ true, "SPAN" ],
michael@0 110 [ true, "DIV" ],
michael@0 111 [ false, "foo" ],
michael@0 112 [ true, "SPAN" ],
michael@0 113 [ true, "DIV" ],
michael@0 114 [ false, "bar" ],
michael@0 115 [ true, "SPAN" ],
michael@0 116 [ true, "DIV" ],
michael@0 117 [ false, "foobar" ],
michael@0 118 ];
michael@0 119 var walker = document.createTreeWalker(document.getElementById('content'),
michael@0 120 NodeFilter.SHOW_ALL,
michael@0 121 {
michael@0 122 acceptNode : function(node) {
michael@0 123 if (node.nodeType == Node.TEXT_NODE &&
michael@0 124 !(/[^\t\n\r ]/.test(node.nodeValue)))
michael@0 125 return NodeFilter.FILTER_REJECT;
michael@0 126 return NodeFilter.FILTER_ACCEPT;
michael@0 127 }
michael@0 128 });
michael@0 129
michael@0 130 walkTree(walker);
michael@0 131
michael@0 132 gIdx = 0;
michael@0 133 }
michael@0 134
michael@0 135 function onlyElementsWalk()
michael@0 136 {
michael@0 137 gResults = [
michael@0 138 [ true, "DIV" ],
michael@0 139 [ true, "DIV" ],
michael@0 140 [ true, "SPAN" ],
michael@0 141 [ true, "DIV" ],
michael@0 142 [ true, "SPAN" ],
michael@0 143 [ true, "SPAN" ],
michael@0 144 [ true, "DIV" ],
michael@0 145 [ true, "SPAN" ],
michael@0 146 [ true, "DIV" ],
michael@0 147 [ true, "SPAN" ],
michael@0 148 [ true, "DIV" ],
michael@0 149 ];
michael@0 150 var walker = document.createTreeWalker(document.getElementById('content'),
michael@0 151 NodeFilter.SHOW_ELEMENT, null);
michael@0 152
michael@0 153 walkTree(walker);
michael@0 154
michael@0 155 gIdx = 0;
michael@0 156 }
michael@0 157
michael@0 158 function onlyDivSubTreeWalk()
michael@0 159 {
michael@0 160 gResults = [
michael@0 161 [ true, "DIV" ],
michael@0 162 [ true, "DIV" ],
michael@0 163 [ false, "foo" ],
michael@0 164 [ true, "DIV" ],
michael@0 165 [ false, "tulip" ],
michael@0 166 [ true, "SPAN" ],
michael@0 167 [ false, "bar" ],
michael@0 168 [ true, "DIV" ],
michael@0 169 [ false, "foo" ],
michael@0 170 [ true, "DIV" ],
michael@0 171 [ false, "bar" ],
michael@0 172 [ true, "DIV" ],
michael@0 173 [ false, "foobar" ],
michael@0 174 ];
michael@0 175 var walker = document.createTreeWalker(document.getElementById('content'),
michael@0 176 NodeFilter.SHOW_ALL,
michael@0 177 {
michael@0 178 acceptNode : function(node) {
michael@0 179 if (node.nodeType == Node.TEXT_NODE &&
michael@0 180 !(/[^\t\n\r ]/.test(node.nodeValue)))
michael@0 181 return NodeFilter.FILTER_REJECT;
michael@0 182
michael@0 183 while (node) {
michael@0 184 if (node.nodeName == "DIV")
michael@0 185 return NodeFilter.FILTER_ACCEPT;
michael@0 186 node = node.parentNode;
michael@0 187 }
michael@0 188 return NodeFilter.FILTER_SKIP;
michael@0 189 }
michael@0 190 });
michael@0 191
michael@0 192 walkTree(walker);
michael@0 193
michael@0 194 gIdx = 0;
michael@0 195 }
michael@0 196
michael@0 197 function onlyDivDataWalk()
michael@0 198 {
michael@0 199 gResults = [
michael@0 200 [ true, "DIV" ],
michael@0 201 [ true, "DIV" ],
michael@0 202 [ false, "foo" ],
michael@0 203 [ true, "DIV" ],
michael@0 204 [ false, "tulip" ],
michael@0 205 [ true, "SPAN" ],
michael@0 206 [ true, "DIV" ],
michael@0 207 [ false, "foo" ],
michael@0 208 [ true, "DIV" ],
michael@0 209 [ false, "bar" ],
michael@0 210 [ true, "DIV" ],
michael@0 211 [ false, "foobar" ],
michael@0 212 ];
michael@0 213 var walker = document.createTreeWalker(document.getElementById('content'),
michael@0 214 NodeFilter.SHOW_ALL,
michael@0 215 {
michael@0 216 acceptNode : function(node) {
michael@0 217 if (node.nodeName == "DIV" ||
michael@0 218 (node.parentNode &&
michael@0 219 node.parentNode.nodeName == "DIV"))
michael@0 220 return NodeFilter.FILTER_ACCEPT;
michael@0 221 return NodeFilter.FILTER_SKIP;
michael@0 222 }
michael@0 223 });
michael@0 224
michael@0 225 walkTree(walker);
michael@0 226
michael@0 227 gIdx = 0;
michael@0 228 }
michael@0 229
michael@0 230 regularWalk();
michael@0 231 noWhiteSpaceWalk();
michael@0 232 onlyElementsWalk();
michael@0 233 onlyDivSubTreeWalk();
michael@0 234 onlyDivDataWalk();
michael@0 235
michael@0 236 </script>
michael@0 237 </pre>
michael@0 238 </body>
michael@0 239 </html>

mercurial