content/base/test/test_bug409380.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=409380
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 409380</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=409380">Mozilla Bug 409380</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 /** Test for Bug 409380 **/
michael@0 21
michael@0 22 function runRangeTest()
michael@0 23 {
michael@0 24 // Bug 336381
michael@0 25 // This is a case which can't be supported (at least not at the moment)
michael@0 26 // because DOM Range requires that when the start boundary point is text node,
michael@0 27 // it must be splitted. But in this case boundary point doesn't have parent,
michael@0 28 // so splitting doesn't work.
michael@0 29 var zz = document.getElementById("connectedDiv").firstChild;
michael@0 30 zz.parentNode.removeChild(zz);
michael@0 31 var range = document.createRange();
michael@0 32 var hadException = false;
michael@0 33 try {
michael@0 34 range.setStart(zz, 0);
michael@0 35 range.setEnd(zz, 0);
michael@0 36 } catch (ex) {
michael@0 37 hadException = true;
michael@0 38 }
michael@0 39 ok(!hadException ,
michael@0 40 "It should be possible to select text node even if the node is not in DOM.");
michael@0 41 hadException = false;
michael@0 42 try {
michael@0 43 range.insertNode(document.createTextNode('5'));
michael@0 44 } catch (ex) {
michael@0 45 hadException = true;
michael@0 46 }
michael@0 47 ok(hadException,
michael@0 48 "It shouldn't be possible to insert text node to a detached range.");
michael@0 49
michael@0 50 // Bug 409380
michael@0 51 var element = document.createElement('div');
michael@0 52 var elementContent = "This is the element content";
michael@0 53 element.innerHTML = elementContent;
michael@0 54 range = element.ownerDocument.createRange();
michael@0 55 hadException = false;
michael@0 56 try {
michael@0 57 range.selectNodeContents(element);
michael@0 58 } catch (ex) {
michael@0 59 hadException = true;
michael@0 60 }
michael@0 61 ok(!hadException,
michael@0 62 "It should be possible to select node contents of a detached element.");
michael@0 63 ok(range.toString() == elementContent, "Wrong range selection");
michael@0 64
michael@0 65 // range.selectNode can't succeed because selectNode sets boundary points
michael@0 66 // to be parentNode, which in this testcase is null.
michael@0 67 element = document.createElement('div');
michael@0 68 range = element.ownerDocument.createRange();
michael@0 69 hadException = false;
michael@0 70 try {
michael@0 71 range.selectNode(element);
michael@0 72 } catch (ex) {
michael@0 73 hadException = true;
michael@0 74 }
michael@0 75 ok(hadException, "It shouldn't be possible to select a detached element.");
michael@0 76
michael@0 77 // Testing contextual fragment.
michael@0 78 range = element.ownerDocument.createRange();
michael@0 79 var cf = null;
michael@0 80 var testContent = "<span>foo</span><span>bar</span>";
michael@0 81 try {
michael@0 82 range.selectNodeContents(element);
michael@0 83 cf = range.createContextualFragment(testContent);
michael@0 84 element.appendChild(cf);
michael@0 85 } catch (ex) {
michael@0 86 }
michael@0 87 ok(cf, "Creating contextual fragment didn't succeed!");
michael@0 88 ok(element.innerHTML == testContent, "Wrong innerHTML!");
michael@0 89
michael@0 90 element = document.createElement('div');
michael@0 91 element.textContent = "foobar";
michael@0 92 range = element.ownerDocument.createRange();
michael@0 93 try {
michael@0 94 range.selectNodeContents(element);
michael@0 95 element.firstChild.insertData(3, " ");
michael@0 96 } catch (ex) {
michael@0 97 }
michael@0 98 ok(range.toString() == "foo bar");
michael@0 99
michael@0 100 // Testing contextual fragment, but inserting element to document
michael@0 101 // after creating range.
michael@0 102 element = document.createElement('div');
michael@0 103 range = element.ownerDocument.createRange();
michael@0 104 document.body.appendChild(element);
michael@0 105 cf = null;
michael@0 106 testContent = "<span>foo</span><span>bar</span>";
michael@0 107 try {
michael@0 108 range.selectNodeContents(element);
michael@0 109 cf = range.createContextualFragment(testContent);
michael@0 110 element.appendChild(cf);
michael@0 111 } catch (ex) {
michael@0 112 }
michael@0 113 ok(cf, "Creating contextual fragment didn't succeed!");
michael@0 114 ok(element.innerHTML == testContent, "Wrong innerHTML!");
michael@0 115
michael@0 116 // Testing contextual fragment, but inserting element to document
michael@0 117 // before creating range.
michael@0 118 element = document.createElement('div');
michael@0 119 document.body.appendChild(element);
michael@0 120 range = element.ownerDocument.createRange();
michael@0 121 cf = null;
michael@0 122 testContent = "<span>foo</span><span>bar</span>";
michael@0 123 try {
michael@0 124 range.selectNodeContents(element);
michael@0 125 cf = range.createContextualFragment(testContent);
michael@0 126 element.appendChild(cf);
michael@0 127 } catch (ex) {
michael@0 128 }
michael@0 129 ok(cf, "Creating contextual fragment didn't succeed!");
michael@0 130 ok(element.innerHTML == testContent, "Wrong innerHTML!");
michael@0 131
michael@0 132 element = document.createElement('div');
michael@0 133 var range2 = element.ownerDocument.createRange();
michael@0 134 hadException = false;
michael@0 135 try {
michael@0 136 range2.selectNodeContents(element);
michael@0 137 } catch (ex) {
michael@0 138 hadException = true;
michael@0 139 }
michael@0 140 ok(!hadException,
michael@0 141 "It should be possible to select node contents of a detached element.");
michael@0 142
michael@0 143 // Now the boundary points of range are in DOM, but boundary points of
michael@0 144 // range2 aren't.
michael@0 145 hadException = false;
michael@0 146 try {
michael@0 147 range.compareBoundaryPoints(range.START_TO_START, range2);
michael@0 148 } catch (ex) {
michael@0 149 hadException = true;
michael@0 150 }
michael@0 151 ok(hadException, "Should have got an exception!");
michael@0 152
michael@0 153 hadException = false;
michael@0 154 try {
michael@0 155 range.compareBoundaryPoints(range.START_TO_END, range2);
michael@0 156 } catch (ex) {
michael@0 157 hadException = true;
michael@0 158 }
michael@0 159 ok(hadException, "Should have got an exception!");
michael@0 160
michael@0 161 hadException = false;
michael@0 162 try {
michael@0 163 range.compareBoundaryPoints(range.END_TO_START, range2);
michael@0 164 } catch (ex) {
michael@0 165 hadException = true;
michael@0 166 }
michael@0 167 ok(hadException, "Should have got an exception!");
michael@0 168
michael@0 169 hadException = false;
michael@0 170 try {
michael@0 171 range.compareBoundaryPoints(range.END_TO_END, range2);
michael@0 172 } catch (ex) {
michael@0 173 hadException = true;
michael@0 174 }
michael@0 175 ok(hadException, "Should have got an exception!");
michael@0 176
michael@0 177 hadException = false;
michael@0 178 try {
michael@0 179 range2.compareBoundaryPoints(range.START_TO_START, range);
michael@0 180 } catch (ex) {
michael@0 181 hadException = true;
michael@0 182 }
michael@0 183 ok(hadException, "Should have got an exception!");
michael@0 184
michael@0 185 hadException = false;
michael@0 186 try {
michael@0 187 range2.compareBoundaryPoints(range.START_TO_END, range);
michael@0 188 } catch (ex) {
michael@0 189 hadException = true;
michael@0 190 }
michael@0 191 ok(hadException, "Should have got an exception!");
michael@0 192
michael@0 193 hadException = false;
michael@0 194 try {
michael@0 195 range2.compareBoundaryPoints(range.END_TO_START, range);
michael@0 196 } catch (ex) {
michael@0 197 hadException = true;
michael@0 198 }
michael@0 199 ok(hadException, "Should have got an exception!");
michael@0 200
michael@0 201 hadException = false;
michael@0 202 try {
michael@0 203 range2.compareBoundaryPoints(range.END_TO_END, range);
michael@0 204 } catch (ex) {
michael@0 205 hadException = true;
michael@0 206 }
michael@0 207 ok(hadException, "Should have got an exception!");
michael@0 208
michael@0 209 // range3 will be in document
michael@0 210 element = document.createElement('div');
michael@0 211 document.body.appendChild(element);
michael@0 212 range3 = element.ownerDocument.createRange();
michael@0 213 hadException = false;
michael@0 214 try {
michael@0 215 range3.selectNodeContents(element);
michael@0 216 } catch (ex) {
michael@0 217 hadException = true;
michael@0 218 }
michael@0 219 ok(!hadException,
michael@0 220 "It should be possible to select node contents of a detached element.");
michael@0 221
michael@0 222 hadException = false;
michael@0 223 try {
michael@0 224 range3.compareBoundaryPoints(range.START_TO_START, range);
michael@0 225 } catch (ex) {
michael@0 226 hadException = true;
michael@0 227 }
michael@0 228 ok(!hadException, "Shouldn't have got an exception!");
michael@0 229
michael@0 230 hadException = false;
michael@0 231 try {
michael@0 232 range3.compareBoundaryPoints(range.START_TO_END, range);
michael@0 233 } catch (ex) {
michael@0 234 hadException = true;
michael@0 235 }
michael@0 236 ok(!hadException, "Shouldn't have got an exception!");
michael@0 237
michael@0 238 hadException = false;
michael@0 239 try {
michael@0 240 range3.compareBoundaryPoints(range.END_TO_START, range);
michael@0 241 } catch (ex) {
michael@0 242 hadException = true;
michael@0 243 }
michael@0 244 ok(!hadException, "Shouldn't have got an exception!");
michael@0 245
michael@0 246 hadException = false;
michael@0 247 try {
michael@0 248 range3.compareBoundaryPoints(range.END_TO_END, range);
michael@0 249 } catch (ex) {
michael@0 250 hadException = true;
michael@0 251 }
michael@0 252 ok(!hadException, "Shouldn't have got an exception!");
michael@0 253
michael@0 254 // range4 won't be in document
michael@0 255 element = document.createElement('div');
michael@0 256 var range4 = element.ownerDocument.createRange();
michael@0 257 hadException = false;
michael@0 258 try {
michael@0 259 range4.selectNodeContents(element);
michael@0 260 } catch (ex) {
michael@0 261 hadException = true;
michael@0 262 }
michael@0 263 ok(!hadException,
michael@0 264 "It should be possible to select node contents of a detached element.");
michael@0 265
michael@0 266 hadException = false;
michael@0 267 try {
michael@0 268 range4.compareBoundaryPoints(range.START_TO_START, range);
michael@0 269 } catch (ex) {
michael@0 270 hadException = true;
michael@0 271 }
michael@0 272 ok(hadException, "Should have got an exception!");
michael@0 273
michael@0 274 hadException = false;
michael@0 275 try {
michael@0 276 range2.compareBoundaryPoints(range.START_TO_END, range);
michael@0 277 } catch (ex) {
michael@0 278 hadException = true;
michael@0 279 }
michael@0 280 ok(hadException, "Should have got an exception!");
michael@0 281
michael@0 282 hadException = false;
michael@0 283 try {
michael@0 284 range4.compareBoundaryPoints(range.END_TO_START, range);
michael@0 285 } catch (ex) {
michael@0 286 hadException = true;
michael@0 287 }
michael@0 288 ok(hadException, "Should have got an exception!");
michael@0 289
michael@0 290 hadException = false;
michael@0 291 try {
michael@0 292 range4.compareBoundaryPoints(range.END_TO_END, range);
michael@0 293 } catch (ex) {
michael@0 294 hadException = true;
michael@0 295 }
michael@0 296 ok(hadException, "Should have got an exception!");
michael@0 297
michael@0 298 // Compare range to itself.
michael@0 299 hadException = false;
michael@0 300 try {
michael@0 301 range.compareBoundaryPoints(range.START_TO_START, range);
michael@0 302 } catch (ex) {
michael@0 303 hadException = true;
michael@0 304 }
michael@0 305 ok(!hadException, "Shouldn't have got an exception!");
michael@0 306
michael@0 307 hadException = false;
michael@0 308 try {
michael@0 309 range.compareBoundaryPoints(range.START_TO_END, range);
michael@0 310 } catch (ex) {
michael@0 311 hadException = true;
michael@0 312 }
michael@0 313 ok(!hadException, "Shouldn't have got an exception!");
michael@0 314
michael@0 315 hadException = false;
michael@0 316 try {
michael@0 317 range.compareBoundaryPoints(range.END_TO_START, range);
michael@0 318 } catch (ex) {
michael@0 319 hadException = true;
michael@0 320 }
michael@0 321 ok(!hadException, "Shouldn't have got an exception!");
michael@0 322
michael@0 323 hadException = false;
michael@0 324 try {
michael@0 325 range.compareBoundaryPoints(range.END_TO_END, range);
michael@0 326 } catch (ex) {
michael@0 327 hadException = true;
michael@0 328 }
michael@0 329 ok(!hadException, "Shouldn't have got an exception!");
michael@0 330
michael@0 331 // Attach startContainer of range2 to document.
michael@0 332 ok(range2.startContainer == range2.endContainer, "Wrong container?");
michael@0 333 document.body.appendChild(range2.startContainer);
michael@0 334
michael@0 335 hadException = false;
michael@0 336 try {
michael@0 337 range2.compareBoundaryPoints(range.START_TO_START, range);
michael@0 338 } catch (ex) {
michael@0 339 hadException = true;
michael@0 340 }
michael@0 341 ok(!hadException, "Shouldn't have got an exception!");
michael@0 342
michael@0 343 hadException = false;
michael@0 344 try {
michael@0 345 range2.compareBoundaryPoints(range.START_TO_END, range);
michael@0 346 } catch (ex) {
michael@0 347 hadException = true;
michael@0 348 }
michael@0 349 ok(!hadException, "Shouldn't have got an exception!");
michael@0 350
michael@0 351 hadException = false;
michael@0 352 try {
michael@0 353 range2.compareBoundaryPoints(range.END_TO_START, range);
michael@0 354 } catch (ex) {
michael@0 355 hadException = true;
michael@0 356 }
michael@0 357 ok(!hadException, "Shouldn't have got an exception!");
michael@0 358
michael@0 359 hadException = false;
michael@0 360 try {
michael@0 361 range2.compareBoundaryPoints(range.END_TO_END, range);
michael@0 362 } catch (ex) {
michael@0 363 hadException = true;
michael@0 364 }
michael@0 365 ok(!hadException, "Shouldn't have got an exception!");
michael@0 366
michael@0 367 SimpleTest.finish();
michael@0 368 }
michael@0 369
michael@0 370 SimpleTest.waitForExplicitFinish();
michael@0 371 addLoadEvent(runRangeTest);
michael@0 372
michael@0 373 </script>
michael@0 374 </pre>
michael@0 375 <div id="connectedDiv">zz</div>
michael@0 376 </body>
michael@0 377 </html>
michael@0 378

mercurial