Wed, 31 Dec 2014 06:09:35 +0100
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=650493 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 650493</title> |
michael@0 | 8 | <script type="text/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=650493">Mozilla Bug 650493</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript"> |
michael@0 | 19 | |
michael@0 | 20 | function getNodes() { |
michael@0 | 21 | var walker = document.createTreeWalker($('content'), NodeFilter.SHOW_ALL, null); |
michael@0 | 22 | var nodes = []; |
michael@0 | 23 | do { |
michael@0 | 24 | nodes.push(walker.currentNode); |
michael@0 | 25 | } while(walker.nextNode()); |
michael@0 | 26 | |
michael@0 | 27 | return nodes; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function check() { |
michael@0 | 31 | var current = getNodes(); |
michael@0 | 32 | is(nodes.length, current.length, "length after " + testName); |
michael@0 | 33 | nodes.forEach(function(val, index) { |
michael@0 | 34 | ok(current.indexOf(val) > -1, "nodes[" + index + "] (" + val + ") shouldn't exist after " + testName); |
michael@0 | 35 | }); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | var nodes = getNodes(); |
michael@0 | 39 | var testName = "empty"; |
michael@0 | 40 | var mutateCount = 0; |
michael@0 | 41 | |
michael@0 | 42 | check(); |
michael@0 | 43 | |
michael@0 | 44 | // Set up listeners |
michael@0 | 45 | root = $('content'); |
michael@0 | 46 | root.addEventListener("DOMNodeInserted", function(e) { |
michael@0 | 47 | mutateCount++; |
michael@0 | 48 | is(e.isTrusted, true, "untrusted mutation event"); |
michael@0 | 49 | var w = document.createTreeWalker(e.target, NodeFilter.SHOW_ALL, null); |
michael@0 | 50 | do { |
michael@0 | 51 | is(nodes.indexOf(w.currentNode), -1, "already have inserted node (" + w.currentNode + ") when " + testName); |
michael@0 | 52 | nodes.push(w.currentNode); |
michael@0 | 53 | } while(w.nextNode()); |
michael@0 | 54 | }, false); |
michael@0 | 55 | root.addEventListener("DOMNodeRemoved", function(e) { |
michael@0 | 56 | mutateCount++; |
michael@0 | 57 | is(e.isTrusted, true, "untrusted mutation event"); |
michael@0 | 58 | var w = document.createTreeWalker(e.target, NodeFilter.SHOW_ALL, null); |
michael@0 | 59 | do { |
michael@0 | 60 | var index = nodes.indexOf(w.currentNode); |
michael@0 | 61 | ok(index != -1, "missing removed node (" + w.currentNode + ") when " + testName); |
michael@0 | 62 | nodes.splice(index, 1); |
michael@0 | 63 | } while(w.nextNode()); |
michael@0 | 64 | }, false); |
michael@0 | 65 | |
michael@0 | 66 | testName = "text-only innerHTML"; |
michael@0 | 67 | root.innerHTML = "hello world"; |
michael@0 | 68 | check(); |
michael@0 | 69 | |
michael@0 | 70 | testName = "innerHTML with <b>"; |
michael@0 | 71 | root.innerHTML = "<b>bold</b> world"; |
michael@0 | 72 | check(); |
michael@0 | 73 | |
michael@0 | 74 | testName = "complex innerHTML"; |
michael@0 | 75 | root.innerHTML = "<b>b<span>old</span></b> <strong>world"; |
michael@0 | 76 | check(); |
michael@0 | 77 | |
michael@0 | 78 | testName = "replacing using .textContent"; |
michael@0 | 79 | root.textContent = "i'm just a plain text minding my own business"; |
michael@0 | 80 | check(); |
michael@0 | 81 | |
michael@0 | 82 | testName = "clearing using .textContent"; |
michael@0 | 83 | root.textContent = ""; |
michael@0 | 84 | check(); |
michael@0 | 85 | |
michael@0 | 86 | testName = "inserting using .textContent"; |
michael@0 | 87 | root.textContent = "i'm new text!!"; |
michael@0 | 88 | check(); |
michael@0 | 89 | |
michael@0 | 90 | testName = "inserting using .textContent"; |
michael@0 | 91 | root.textContent = "i'm new text!!"; |
michael@0 | 92 | check(); |
michael@0 | 93 | |
michael@0 | 94 | testName = "preparing to normalize"; |
michael@0 | 95 | root.innerHTML = "<u><b>foo</b></u> "; |
michael@0 | 96 | var u = root.firstChild; |
michael@0 | 97 | is(u.nodeName, "U", "got the right node"); |
michael@0 | 98 | var b = u.firstChild; |
michael@0 | 99 | is(b.nodeName, "B", "got the right node"); |
michael@0 | 100 | b.insertBefore(document.createTextNode(""), b.firstChild); |
michael@0 | 101 | b.insertBefore(document.createTextNode(""), b.firstChild); |
michael@0 | 102 | b.appendChild(document.createTextNode("")); |
michael@0 | 103 | b.appendChild(document.createTextNode("hello")); |
michael@0 | 104 | b.appendChild(document.createTextNode("world")); |
michael@0 | 105 | u.appendChild(document.createTextNode("foo")); |
michael@0 | 106 | u.appendChild(document.createTextNode("")); |
michael@0 | 107 | u.appendChild(document.createTextNode("bar")); |
michael@0 | 108 | check(); |
michael@0 | 109 | |
michael@0 | 110 | testName = "normalizing"; |
michael@0 | 111 | root.normalize(); |
michael@0 | 112 | check(); |
michael@0 | 113 | |
michael@0 | 114 | testName = "self replace firstChild"; |
michael@0 | 115 | mutateCount = 0; |
michael@0 | 116 | root.replaceChild(root.firstChild, root.firstChild); |
michael@0 | 117 | check(); |
michael@0 | 118 | is(mutateCount, 2, "should remove and reinsert " + testName); |
michael@0 | 119 | |
michael@0 | 120 | testName = "self replace second child"; |
michael@0 | 121 | mutateCount = 0; |
michael@0 | 122 | root.replaceChild(root.firstChild.nextSibling, root.firstChild.nextSibling); |
michael@0 | 123 | check(); |
michael@0 | 124 | is(mutateCount, 2, "should remove and reinsert " + testName); |
michael@0 | 125 | |
michael@0 | 126 | testName = "self replace lastChild"; |
michael@0 | 127 | mutateCount = 0; |
michael@0 | 128 | root.replaceChild(root.lastChild, root.lastChild); |
michael@0 | 129 | check(); |
michael@0 | 130 | is(mutateCount, 2, "should remove and reinsert " + testName); |
michael@0 | 131 | |
michael@0 | 132 | testName = "self insertBefore firstChild"; |
michael@0 | 133 | mutateCount = 0; |
michael@0 | 134 | root.insertBefore(root.firstChild, root.firstChild); |
michael@0 | 135 | check(); |
michael@0 | 136 | is(mutateCount, 2, "should remove and reinsert " + testName); |
michael@0 | 137 | |
michael@0 | 138 | testName = "self insertBefore second child"; |
michael@0 | 139 | mutateCount = 0; |
michael@0 | 140 | root.insertBefore(root.firstChild.nextSibling, root.firstChild.nextSibling); |
michael@0 | 141 | check(); |
michael@0 | 142 | is(mutateCount, 2, "should remove and reinsert " + testName); |
michael@0 | 143 | |
michael@0 | 144 | testName = "self insertBefore lastChild"; |
michael@0 | 145 | mutateCount = 0; |
michael@0 | 146 | root.insertBefore(root.lastChild, root.lastChild); |
michael@0 | 147 | check(); |
michael@0 | 148 | is(mutateCount, 2, "should remove and reinsert " + testName); |
michael@0 | 149 | |
michael@0 | 150 | testName = "appendChild last"; |
michael@0 | 151 | mutateCount = 0; |
michael@0 | 152 | root.appendChild(root.lastChild); |
michael@0 | 153 | check(); |
michael@0 | 154 | is(mutateCount, 2, "should remove and reinsert " + testName); |
michael@0 | 155 | |
michael@0 | 156 | testName = "prepare script/style"; |
michael@0 | 157 | script = document.createElement("script"); |
michael@0 | 158 | script.appendChild(document.createTextNode("void(0);")); |
michael@0 | 159 | root.appendChild(script); |
michael@0 | 160 | style = document.createElement("style"); |
michael@0 | 161 | root.appendChild(style); |
michael@0 | 162 | check(); |
michael@0 | 163 | |
michael@0 | 164 | testName = "set something in script"; |
michael@0 | 165 | script.text = "something"; |
michael@0 | 166 | check(); |
michael@0 | 167 | |
michael@0 | 168 | testName = "set something in style"; |
michael@0 | 169 | style.innerHTML = "something { dislay: none; }"; |
michael@0 | 170 | check(); |
michael@0 | 171 | |
michael@0 | 172 | testName = "moving style"; |
michael@0 | 173 | root.insertBefore(style, root.firstChild); |
michael@0 | 174 | check(); |
michael@0 | 175 | |
michael@0 | 176 | testName = "replacing script"; |
michael@0 | 177 | root.replaceChild(b, script); |
michael@0 | 178 | check(); |
michael@0 | 179 | |
michael@0 | 180 | testName = "doc-fragment insert in the middle"; |
michael@0 | 181 | frag = document.createDocumentFragment(); |
michael@0 | 182 | frag.addEventListener("DOMNodeRemoved", function(e) { |
michael@0 | 183 | var index = children.indexOf(e.target); |
michael@0 | 184 | ok(index != -1, "unknown child removed from fragment"); |
michael@0 | 185 | children.splice(index, 1); |
michael@0 | 186 | }, false); |
michael@0 | 187 | var children = []; |
michael@0 | 188 | children.push(document.createTextNode("foo")); |
michael@0 | 189 | children.push(document.createTextNode("bar")); |
michael@0 | 190 | children.push(document.createElement("span")); |
michael@0 | 191 | children.push(document.createElement("b")); |
michael@0 | 192 | children[2].appendChild(document.createElement("i")); |
michael@0 | 193 | children.forEach(function(child) { frag.appendChild(child); }); |
michael@0 | 194 | ok(root.firstChild, "need to have children in order to test inserting before end"); |
michael@0 | 195 | root.replaceChild(frag, root.firstChild); |
michael@0 | 196 | check(); |
michael@0 | 197 | is(children.length, 0, "should have received DOMNodeRemoved for all frag children when inserting"); |
michael@0 | 198 | is(frag.childNodes.length, 0, "fragment should be empty when inserting"); |
michael@0 | 199 | |
michael@0 | 200 | testName = "doc-fragment append at the end"; |
michael@0 | 201 | children.push(document.createTextNode("foo")); |
michael@0 | 202 | children.push(document.createTextNode("bar")); |
michael@0 | 203 | children.push(document.createElement("span")); |
michael@0 | 204 | children.push(document.createElement("b")); |
michael@0 | 205 | children[2].appendChild(document.createElement("i")); |
michael@0 | 206 | children.forEach(function(child) { frag.appendChild(child); }); |
michael@0 | 207 | root.appendChild(frag); |
michael@0 | 208 | check(); |
michael@0 | 209 | is(children.length, 0, "should have received DOMNodeRemoved for all frag children when appending"); |
michael@0 | 210 | is(frag.childNodes.length, 0, "fragment should be empty when appending"); |
michael@0 | 211 | |
michael@0 | 212 | </script> |
michael@0 | 213 | </body> |
michael@0 | 214 | </html> |
michael@0 | 215 |