test_bug98997.html (4780B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=98997 5 --> 6 <head> 7 <title>Test for Bug 98997</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 <style type="text/css"> 11 12 /* 13 * This test does NOT test any of the cases where :empty and 14 * :-moz-only-whitespace differ. We should probably have some tests 15 * for that as well. 16 */ 17 div.test { width: 200px; height: 30px; margin: 5px 0; } 18 div.test.to, div.test.from:empty { background: orange; } 19 div.test.to:empty, div.test.from { background: green; } 20 div.test.to, div.test.from:-moz-only-whitespace { color: maroon; } 21 div.test.to:-moz-only-whitespace, div.test.from { color: navy; } 22 23 </style> 24 </head> 25 <body> 26 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=98997">Mozilla Bug 98997</a> 27 <div id="display"> 28 <div class="test to" onclick="testReplaceChild(this, '')">x</div> 29 <div class="test to" onclick="testReplaceChild(this, '')"><span>x</span></div> 30 <div class="test to" onclick="testReplaceChild(this, '')">x<!-- comment --></div> 31 <div class="test to" onclick="testRemoveChild(this)">x</div> 32 <div class="test to" onclick="testRemoveChild(this)"><span>x</span></div> 33 <div class="test to" onclick="testRemoveChild(this)">x<!-- comment --></div> 34 <div class="test to" onclick="testChangeData(this, '')">x</div> 35 <div class="test to" onclick="testChangeData(this, '')">x<!-- comment --></div> 36 <div class="test to" onclick="testDeleteData(this)">x</div> 37 <div class="test to" onclick="testDeleteData(this)">x<!-- comment --></div> 38 <div class="test to" onclick="testReplaceData(this, '')">x</div> 39 <div class="test to" onclick="testReplaceData(this, '')">x<!-- comment --></div> 40 41 <div class="test from makeemptytext" onclick="testReplaceChild(this, 'x')"></div> 42 <div class="test from makeemptytext" onclick="testReplaceChild(this, 'x')"><!-- comment --></div> 43 <div class="test from" onclick="testReplaceChild(this, 'x')"><!-- comment --></div> 44 <div class="test from" onclick="testInsertBefore(this, 'x')"></div> 45 <div class="test from" onclick="testInsertBefore(this, 'x')"><!-- comment --></div> 46 <div class="test from" onclick="testAppendChild(this, 'x')"></div> 47 <div class="test from" onclick="testAppendChild(this, 'x')"><!-- comment --></div> 48 <div class="test from makeemptytext" onclick="testChangeData(this, 'x')"></div> 49 <div class="test from makeemptytext" onclick="testChangeData(this, 'x')"><!-- comment --></div> 50 <div class="test from makeemptytext" onclick="testAppendData(this, 'x')"></div> 51 <div class="test from makeemptytext" onclick="testAppendData(this, 'x')"><!-- comment --></div> 52 <div class="test from makeemptytext" onclick="testReplaceData(this, 'x')"></div> 53 <div class="test from makeemptytext" onclick="testReplaceData(this, 'x')"><!-- comment --></div> 54 </div> 55 56 <div id="content" style="display: none"> 57 58 </div> 59 <pre id="test"> 60 <script class="testbody" type="text/javascript"> 61 62 /** Test for Bug 98997 */ 63 64 function testInsertBefore(elt, text) { 65 elt.insertBefore(document.createTextNode(text), elt.firstChild); 66 } 67 68 function testAppendChild(elt, text) { 69 elt.appendChild(document.createTextNode(text)); 70 } 71 72 function testReplaceChild(elt, text) { 73 elt.replaceChild(document.createTextNode(text), elt.firstChild); 74 } 75 76 function testRemoveChild(elt) { 77 elt.firstChild.remove(); 78 } 79 80 function testChangeData(elt, text) { 81 elt.firstChild.data = text; 82 } 83 84 function testAppendData(elt, text) { 85 elt.firstChild.appendData(text); 86 } 87 88 function testDeleteData(elt) { 89 elt.firstChild.deleteData(0, elt.firstChild.length); 90 } 91 92 function testReplaceData(elt, text) { 93 elt.firstChild.replaceData(0, elt.firstChild.length, text); 94 } 95 96 var cnodes = document.getElementById("display").childNodes; 97 var divs = []; 98 var i; 99 for (i = 0; i < cnodes.length; ++i) { 100 if (cnodes[i].nodeName == "DIV") 101 divs.push(cnodes[i]); 102 } 103 104 for (i in divs) { 105 let div = divs[i]; 106 if (div.className.match(/makeemptytext/)) 107 div.insertBefore(document.createTextNode(""), div.firstChild); 108 } 109 110 const ORANGE = "rgb(255, 165, 0)"; 111 const MAROON = "rgb(128, 0, 0)"; 112 const GREEN = "rgb(0, 128, 0)"; 113 const NAVY = "rgb(0, 0, 128)"; 114 115 function color(div) { 116 return getComputedStyle(div, "").color; 117 } 118 function bg(div) { 119 return getComputedStyle(div, "").backgroundColor; 120 } 121 122 for (i in divs) { 123 let div = divs[i]; 124 is(bg(div), ORANGE, "should be orange"); 125 is(color(div), MAROON, "should be maroon"); 126 } 127 128 for (i in divs) { 129 let div = divs[i]; 130 var e = document.createEvent("MouseEvents"); 131 e.initEvent("click", true, true); 132 div.dispatchEvent(e); 133 } 134 135 for (i in divs) { 136 let div = divs[i]; 137 is(bg(div), GREEN, "should be green"); 138 is(color(div), NAVY, "should be navy"); 139 } 140 141 </script> 142 </pre> 143 </body> 144 </html>