1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/test/test_bug650493.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,215 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=650493 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 650493</title> 1.11 + <script type="text/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=650493">Mozilla Bug 650493</a> 1.16 +<p id="display"></p> 1.17 +<div id="content" style="display: none"> 1.18 + 1.19 +</div> 1.20 +<pre id="test"> 1.21 +<script class="testbody" type="text/javascript"> 1.22 + 1.23 +function getNodes() { 1.24 + var walker = document.createTreeWalker($('content'), NodeFilter.SHOW_ALL, null); 1.25 + var nodes = []; 1.26 + do { 1.27 + nodes.push(walker.currentNode); 1.28 + } while(walker.nextNode()); 1.29 + 1.30 + return nodes; 1.31 +} 1.32 + 1.33 +function check() { 1.34 + var current = getNodes(); 1.35 + is(nodes.length, current.length, "length after " + testName); 1.36 + nodes.forEach(function(val, index) { 1.37 + ok(current.indexOf(val) > -1, "nodes[" + index + "] (" + val + ") shouldn't exist after " + testName); 1.38 + }); 1.39 +} 1.40 + 1.41 +var nodes = getNodes(); 1.42 +var testName = "empty"; 1.43 +var mutateCount = 0; 1.44 + 1.45 +check(); 1.46 + 1.47 +// Set up listeners 1.48 +root = $('content'); 1.49 +root.addEventListener("DOMNodeInserted", function(e) { 1.50 + mutateCount++; 1.51 + is(e.isTrusted, true, "untrusted mutation event"); 1.52 + var w = document.createTreeWalker(e.target, NodeFilter.SHOW_ALL, null); 1.53 + do { 1.54 + is(nodes.indexOf(w.currentNode), -1, "already have inserted node (" + w.currentNode + ") when " + testName); 1.55 + nodes.push(w.currentNode); 1.56 + } while(w.nextNode()); 1.57 +}, false); 1.58 +root.addEventListener("DOMNodeRemoved", function(e) { 1.59 + mutateCount++; 1.60 + is(e.isTrusted, true, "untrusted mutation event"); 1.61 + var w = document.createTreeWalker(e.target, NodeFilter.SHOW_ALL, null); 1.62 + do { 1.63 + var index = nodes.indexOf(w.currentNode); 1.64 + ok(index != -1, "missing removed node (" + w.currentNode + ") when " + testName); 1.65 + nodes.splice(index, 1); 1.66 + } while(w.nextNode()); 1.67 +}, false); 1.68 + 1.69 +testName = "text-only innerHTML"; 1.70 +root.innerHTML = "hello world"; 1.71 +check(); 1.72 + 1.73 +testName = "innerHTML with <b>"; 1.74 +root.innerHTML = "<b>bold</b> world"; 1.75 +check(); 1.76 + 1.77 +testName = "complex innerHTML"; 1.78 +root.innerHTML = "<b>b<span>old</span></b> <strong>world"; 1.79 +check(); 1.80 + 1.81 +testName = "replacing using .textContent"; 1.82 +root.textContent = "i'm just a plain text minding my own business"; 1.83 +check(); 1.84 + 1.85 +testName = "clearing using .textContent"; 1.86 +root.textContent = ""; 1.87 +check(); 1.88 + 1.89 +testName = "inserting using .textContent"; 1.90 +root.textContent = "i'm new text!!"; 1.91 +check(); 1.92 + 1.93 +testName = "inserting using .textContent"; 1.94 +root.textContent = "i'm new text!!"; 1.95 +check(); 1.96 + 1.97 +testName = "preparing to normalize"; 1.98 +root.innerHTML = "<u><b>foo</b></u> "; 1.99 +var u = root.firstChild; 1.100 +is(u.nodeName, "U", "got the right node"); 1.101 +var b = u.firstChild; 1.102 +is(b.nodeName, "B", "got the right node"); 1.103 +b.insertBefore(document.createTextNode(""), b.firstChild); 1.104 +b.insertBefore(document.createTextNode(""), b.firstChild); 1.105 +b.appendChild(document.createTextNode("")); 1.106 +b.appendChild(document.createTextNode("hello")); 1.107 +b.appendChild(document.createTextNode("world")); 1.108 +u.appendChild(document.createTextNode("foo")); 1.109 +u.appendChild(document.createTextNode("")); 1.110 +u.appendChild(document.createTextNode("bar")); 1.111 +check(); 1.112 + 1.113 +testName = "normalizing"; 1.114 +root.normalize(); 1.115 +check(); 1.116 + 1.117 +testName = "self replace firstChild"; 1.118 +mutateCount = 0; 1.119 +root.replaceChild(root.firstChild, root.firstChild); 1.120 +check(); 1.121 +is(mutateCount, 2, "should remove and reinsert " + testName); 1.122 + 1.123 +testName = "self replace second child"; 1.124 +mutateCount = 0; 1.125 +root.replaceChild(root.firstChild.nextSibling, root.firstChild.nextSibling); 1.126 +check(); 1.127 +is(mutateCount, 2, "should remove and reinsert " + testName); 1.128 + 1.129 +testName = "self replace lastChild"; 1.130 +mutateCount = 0; 1.131 +root.replaceChild(root.lastChild, root.lastChild); 1.132 +check(); 1.133 +is(mutateCount, 2, "should remove and reinsert " + testName); 1.134 + 1.135 +testName = "self insertBefore firstChild"; 1.136 +mutateCount = 0; 1.137 +root.insertBefore(root.firstChild, root.firstChild); 1.138 +check(); 1.139 +is(mutateCount, 2, "should remove and reinsert " + testName); 1.140 + 1.141 +testName = "self insertBefore second child"; 1.142 +mutateCount = 0; 1.143 +root.insertBefore(root.firstChild.nextSibling, root.firstChild.nextSibling); 1.144 +check(); 1.145 +is(mutateCount, 2, "should remove and reinsert " + testName); 1.146 + 1.147 +testName = "self insertBefore lastChild"; 1.148 +mutateCount = 0; 1.149 +root.insertBefore(root.lastChild, root.lastChild); 1.150 +check(); 1.151 +is(mutateCount, 2, "should remove and reinsert " + testName); 1.152 + 1.153 +testName = "appendChild last"; 1.154 +mutateCount = 0; 1.155 +root.appendChild(root.lastChild); 1.156 +check(); 1.157 +is(mutateCount, 2, "should remove and reinsert " + testName); 1.158 + 1.159 +testName = "prepare script/style"; 1.160 +script = document.createElement("script"); 1.161 +script.appendChild(document.createTextNode("void(0);")); 1.162 +root.appendChild(script); 1.163 +style = document.createElement("style"); 1.164 +root.appendChild(style); 1.165 +check(); 1.166 + 1.167 +testName = "set something in script"; 1.168 +script.text = "something"; 1.169 +check(); 1.170 + 1.171 +testName = "set something in style"; 1.172 +style.innerHTML = "something { dislay: none; }"; 1.173 +check(); 1.174 + 1.175 +testName = "moving style"; 1.176 +root.insertBefore(style, root.firstChild); 1.177 +check(); 1.178 + 1.179 +testName = "replacing script"; 1.180 +root.replaceChild(b, script); 1.181 +check(); 1.182 + 1.183 +testName = "doc-fragment insert in the middle"; 1.184 +frag = document.createDocumentFragment(); 1.185 +frag.addEventListener("DOMNodeRemoved", function(e) { 1.186 + var index = children.indexOf(e.target); 1.187 + ok(index != -1, "unknown child removed from fragment"); 1.188 + children.splice(index, 1); 1.189 +}, false); 1.190 +var children = []; 1.191 +children.push(document.createTextNode("foo")); 1.192 +children.push(document.createTextNode("bar")); 1.193 +children.push(document.createElement("span")); 1.194 +children.push(document.createElement("b")); 1.195 +children[2].appendChild(document.createElement("i")); 1.196 +children.forEach(function(child) { frag.appendChild(child); }); 1.197 +ok(root.firstChild, "need to have children in order to test inserting before end"); 1.198 +root.replaceChild(frag, root.firstChild); 1.199 +check(); 1.200 +is(children.length, 0, "should have received DOMNodeRemoved for all frag children when inserting"); 1.201 +is(frag.childNodes.length, 0, "fragment should be empty when inserting"); 1.202 + 1.203 +testName = "doc-fragment append at the end"; 1.204 +children.push(document.createTextNode("foo")); 1.205 +children.push(document.createTextNode("bar")); 1.206 +children.push(document.createElement("span")); 1.207 +children.push(document.createElement("b")); 1.208 +children[2].appendChild(document.createElement("i")); 1.209 +children.forEach(function(child) { frag.appendChild(child); }); 1.210 +root.appendChild(frag); 1.211 +check(); 1.212 +is(children.length, 0, "should have received DOMNodeRemoved for all frag children when appending"); 1.213 +is(frag.childNodes.length, 0, "fragment should be empty when appending"); 1.214 + 1.215 +</script> 1.216 +</body> 1.217 +</html> 1.218 +