1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug498240.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,254 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=498240 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 498240</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 +<style> 1.14 + .container { border: 1px solid blue; display:block; } 1.15 + b { color:blue; } 1.16 + i { color:magenta; } 1.17 +</style> 1.18 +</head> 1.19 +<body> 1.20 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=498240">Mozilla Bug 498240</a> 1.21 +<p id="display"></p> 1.22 +<div id="content" style="display: none"> 1.23 + 1.24 +</div> 1.25 +<pre id="test"> 1.26 +<script type="application/javascript"> 1.27 + 1.28 +/** Test for Bug 498240 **/ 1.29 + 1.30 + 1.31 +function create(s) { 1.32 + var p = document.createElement('span'); 1.33 + p.innerHTML = s; 1.34 + p.setAttribute("class","container"); 1.35 + document.body.appendChild(p); 1.36 + return p; 1.37 +} 1.38 +function select(start, startOffset, end, endOffset) { 1.39 + var sel = getSelection(); 1.40 + sel.removeAllRanges(); 1.41 + var range = document.createRange(); 1.42 + range.setStart(start, startOffset); 1.43 + range.setEnd(end, endOffset); 1.44 + sel.addRange(range); 1.45 +} 1.46 + 1.47 +function insertClone(node) { 1.48 + var sel = getSelection(); 1.49 + var range = sel.getRangeAt(0); 1.50 + range.insertNode(node.cloneNode(true)); 1.51 +} 1.52 +function insertCloneAtEnd(node) { 1.53 + var sel = getSelection(); 1.54 + var range = sel.getRangeAt(0); 1.55 + range.endContainer.insertBefore(node.cloneNode(true),range.endContainer.childNodes[range.endOffset]); 1.56 +} 1.57 + 1.58 +function check(start, startOffset, end, endOffset, s) { 1.59 + var sel = getSelection(); 1.60 + var range = sel.getRangeAt(0); 1.61 + is(range.startContainer, start, "wrong start node for range: '"+range.toString()+"'"); 1.62 + is(range.startOffset, startOffset, "wrong start offset for range: '"+range.toString()+"'"); 1.63 + is(range.endContainer, end, "wrong end node for range: '"+range.toString()+"'"); 1.64 + is(range.endOffset, endOffset, "wrong end offset for range: '"+range.toString()+"'"); 1.65 +} 1.66 + 1.67 +function testInsertNode(node) { 1.68 + var p; 1.69 + 1.70 + p = create('a<b>bc</b>'); 1.71 + select(p.childNodes[0],0,p.childNodes[1],0); 1.72 + insertClone(node); 1.73 + check(p.childNodes[0],0,p.childNodes[3],0); 1.74 + 1.75 + p = create('d<b>ef</b>'); 1.76 + select(p.childNodes[0],0,p.childNodes[1],1); 1.77 + insertClone(node); 1.78 + check(p.childNodes[0],0,p.childNodes[3],1); 1.79 + 1.80 + p = create('g<b>h</b>'); 1.81 + select(p.childNodes[0],0,p.childNodes[0],0); 1.82 + insertClone(node); 1.83 + check(p.childNodes[0],0,p,2); 1.84 + 1.85 + p = create('i<b>j</b>'); 1.86 + select(p.childNodes[0],1,p.childNodes[0],1); 1.87 + insertClone(node); 1.88 + check(p.childNodes[0],1,p,2); 1.89 + 1.90 + p = create('k<b>l</b>'); 1.91 + select(p.childNodes[0],0,p.childNodes[1].childNodes[0],0); 1.92 + insertClone(node); 1.93 + check(p.childNodes[0],0,p.childNodes[3].childNodes[0],0); 1.94 + 1.95 + p = create('m<b>no</b>'); 1.96 + select(p.childNodes[0],1,p.childNodes[1].childNodes[0],0); 1.97 + insertClone(node); 1.98 + check(p.childNodes[0],1,p.childNodes[3].childNodes[0],0); 1.99 + 1.100 + p = create('p<b>qr</b>'); 1.101 + select(p.childNodes[0],1,p.childNodes[1].childNodes[0],1); 1.102 + insertClone(node); 1.103 + check(p.childNodes[0],1,p.childNodes[3].childNodes[0],1); 1.104 + 1.105 + p = create('s<b>tu</b>'); 1.106 + select(p.childNodes[0],1,p.childNodes[1],0); 1.107 + insertClone(node); 1.108 + check(p.childNodes[0],1,p.childNodes[3],0); 1.109 + 1.110 + p = create('<i>A</i><b>BC</b>'); 1.111 + select(p.childNodes[0],0,p.childNodes[1],0); 1.112 + insertClone(node); 1.113 + check(p.childNodes[0],0,p.childNodes[1],0); 1.114 + 1.115 + p = create('<i>D</i><b>EF</b>'); 1.116 + select(p.childNodes[0],1,p.childNodes[1],1); 1.117 + insertClone(node); 1.118 + check(p.childNodes[0],1,p.childNodes[1],1); 1.119 + 1.120 + p = create('<i></i><b>GH</b>'); 1.121 + select(p.childNodes[0],0,p.childNodes[1],0); 1.122 + insertClone(node); 1.123 + check(p.childNodes[0],0,p.childNodes[1],0); 1.124 + 1.125 + p = create('<i>I</i><b>J</b>'); 1.126 + select(p,0,p.childNodes[1],0); 1.127 + insertClone(node); 1.128 + check(p,0,p.childNodes[2],0); 1.129 + 1.130 + p = create('<i>K</i><b>L</b>'); 1.131 + select(p,0,p,2); 1.132 + insertClone(node); 1.133 + check(p,0,p,3); 1.134 + 1.135 + p = create('<i>M</i><b>N</b>'); 1.136 + select(p,1,p,2); 1.137 + insertClone(node); 1.138 + check(p,1,p,3); 1.139 + 1.140 + p = create('<i>O</i><b>P</b>'); 1.141 + select(p,1,p,1); 1.142 + insertClone(node); 1.143 + check(p,1,p,2); 1.144 + 1.145 + p = create('<i>Q</i><b>R</b>'); 1.146 + select(p,2,p,2); 1.147 + insertClone(node); 1.148 + check(p,2,p,3); 1.149 + 1.150 + p = create('<i>S</i><b>T</b>'); 1.151 + select(p,1,p,1); 1.152 + insertCloneAtEnd(node); 1.153 + check(p,1,p,1); 1.154 + 1.155 + p = create('<i>U</i><b>V</b>'); 1.156 + select(p,2,p,2); 1.157 + insertCloneAtEnd(node); 1.158 + check(p,2,p,2); 1.159 + 1.160 + p = create('<i>X</i><b>Y</b>'); 1.161 + select(p,0,p,1); 1.162 + insertCloneAtEnd(node); 1.163 + check(p,0,p,1); 1.164 + 1.165 + p = create('<i>X</i><b><s>Y</s></b>'); 1.166 + select(p,0,p.childNodes[1],1); 1.167 + insertCloneAtEnd(node); 1.168 + check(p,0,p.childNodes[1],1); 1.169 + 1.170 + p = create('<i>Z</i><b></b>'); 1.171 + select(p,0,p.childNodes[1],0); 1.172 + insertCloneAtEnd(node); 1.173 + check(p,0,p.childNodes[1],0); 1.174 + 1.175 + p = create('<i>ZA</i><b><s>ZB</s><u>ZC</u></b>'); 1.176 + select(p,0,p.childNodes[1],1); 1.177 + insertCloneAtEnd(node); 1.178 + check(p,0,p.childNodes[1],1); 1.179 +} 1.180 +function testInvalidNodeType(node) { 1.181 + try { 1.182 + testInsertNode(node); 1.183 + ok(false,"Expected an InvalidNodeTypeError"); 1.184 + } catch(e) { 1.185 + is(e.name, "InvalidNodeTypeError", "Wrong exception, expected InvalidNodeTypeError"); 1.186 + ok(e instanceof DOMException, "Wrong type of exception: " + e); 1.187 + is(e.code, DOMException.INVALID_NODE_TYPE_ERR, "Wrong exception code, expected INVALID_NODE_TYPE_ERR"); 1.188 + } 1.189 +} 1.190 + 1.191 +function runTest() { 1.192 + testInsertNode(document.createTextNode('123')); 1.193 + 1.194 + var i = document.createElement('SPAN') 1.195 + i.innerHTML='456' 1.196 + testInsertNode(i); 1.197 + 1.198 + i = document.createDocumentFragment(); 1.199 + i.appendChild(document.createTextNode('789')); 1.200 + testInsertNode(i); 1.201 + 1.202 + /// DOM2 Traversal and Range Specification 2.13 "insertNode": 1.203 + /// RangeException INVALID_NODE_TYPE_ERR: Raised if newNode is an Attr, Entity, Notation, or Document node. 1.204 + // BUG: testInvalidNodeType(document.createAttribute('a')); 1.205 + todo(false, "Test insertion of Entity node into range"); 1.206 + // TODO: testInvalidNodeType(document.createEntity()); 1.207 + todo(false, "Test insertion of Notation node into range"); 1.208 + // TODO: testInvalidNodeType(document.createNotation()); 1.209 + // BUG: testInvalidNodeType(document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null)); 1.210 + 1.211 + // Intentionally fails because of bug 418755. 1.212 + todo(false, "test that Range::insertNode() throws WrongDocumentError when it should"); 1.213 + i = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null).createElement('html'); 1.214 + try { 1.215 + testInsertNode(i); 1.216 + todo(false,"Expected a WrongDocumentError"); 1.217 + } catch(e) { 1.218 + is(e.name, "WrongDocumentError", "Wrong exception, expected WrongDocumentError"); 1.219 + ok(e instanceof DOMException, "Wrong type of exception: " + e); 1.220 + is(e.code, DOMException.WRONG_DOCUMENT_ERR, "Wrong exception code, expected WRONG_DOCUMENT_ERR"); 1.221 + } 1.222 + 1.223 + // Inserting an ancestor of the start container should throw HierarchyRequestError 1.224 + todo(false, "test that Range::insertNode() throws HierarchyRequestError when it should"); 1.225 + var p = create('<b>IJK</b>'); 1.226 + select(p.childNodes[0],0,p.childNodes[0],1); 1.227 + var sel = getSelection(); 1.228 + var range = sel.getRangeAt(0); 1.229 + try { 1.230 + range.insertNode(p); 1.231 + ok(false,"Expected a HierarchyRequestError"); 1.232 + } catch(e) { 1.233 + is(e.name, "HierarchyRequestError", "Wrong exception, expected HierarchyRequestError"); 1.234 + ok(e instanceof DOMException, "Wrong type of exception: " + e); 1.235 + is(e.code, DOMException.HIERARCHY_REQUEST_ERR, "Wrong exception code, expected HIERARCHY_REQUEST_ERR"); 1.236 + } 1.237 + 1.238 + // TODO: we should also have a test for: 1.239 + /// "HierarchyRequestError: Raised if the container of the start of the Range is of a type 1.240 + /// that does not allow children of the type of newNode" 1.241 + 1.242 + todo(false, "InvalidStateError test goes here..."); 1.243 + 1.244 + var sel = getSelection(); 1.245 + sel.removeAllRanges(); 1.246 + 1.247 + SimpleTest.finish(); 1.248 +} 1.249 + 1.250 +SimpleTest.waitForExplicitFinish(); 1.251 +addLoadEvent(runTest); 1.252 + 1.253 + 1.254 +</script> 1.255 +</pre> 1.256 +</body> 1.257 +</html>