Selection_addRange.html (74974B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>focus move tests caused by a call of Selection.addRange()</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <body> 7 <div style="height: 3000px;">Spacer to check whether or not page was scrolled down to focused editor</div> 8 <p id="staticBefore">static text</p> 9 <div id="editor" contenteditable><p>content of editor</p></div> 10 <div id="outerEditor" contenteditable 11 ><p>content of outer editor</p><div id="staticInEditor" contenteditable="false" 12 ><p>static content of outer editor</p><div id="innerEditor" contenteditable 13 ><p>content of inner editor</p></div></div></div> 14 <p id="staticAfter">static text</p> 15 <p><a id="anchor" href="about:blank">anchor</a></p> 16 <script> 17 "use strict"; 18 19 var staticBefore = { 20 element: document.getElementById("staticBefore"), 21 textNode: document.getElementById("staticBefore").firstChild, 22 textLength: document.getElementById("staticBefore").firstChild.length 23 }; 24 var editor = { 25 element: document.getElementById("editor"), 26 textNode: document.getElementById("editor").firstChild.firstChild, 27 textLength: document.getElementById("editor").firstChild.firstChild.length 28 }; 29 var outerEditor = { 30 element: document.getElementById("outerEditor"), 31 textNode: document.getElementById("outerEditor").firstChild.firstChild, 32 textLength: document.getElementById("outerEditor").firstChild.firstChild.length 33 }; 34 var staticInEditor = { 35 element: document.getElementById("staticInEditor"), 36 textNode: document.getElementById("staticInEditor").firstChild, 37 textLength: document.getElementById("staticInEditor").firstChild.length 38 }; 39 var innerEditor = { 40 element: document.getElementById("innerEditor"), 41 textNode: document.getElementById("innerEditor").firstChild.firstChild, 42 textLength: document.getElementById("innerEditor").firstChild.firstChild.length 43 }; 44 var staticAfter = { 45 element: document.getElementById("staticAfter"), 46 textNode: document.getElementById("staticAfter").firstChild, 47 textLength: document.getElementById("staticAfter").firstChild.length 48 }; 49 var anchor = { 50 element: document.getElementById("anchor"), 51 textNode: document.getElementById("anchor").firstChild, 52 textLength: document.getElementById("anchor").firstChild.length 53 }; 54 55 function resetFocusAndSelectionRange(aFocus) 56 { 57 document.getSelection().removeAllRanges(); 58 if (document.activeElement) { 59 document.activeElement.blur(); 60 } 61 if (aFocus) { 62 aFocus.element.focus(); 63 document.getSelection().collapse(aFocus.textNode, 0); 64 } else { 65 document.getSelection().collapse(staticBefore.textNode, 0); 66 } 67 document.documentElement.scrollTop = 0; 68 } 69 70 /** 71 * NOTE: When you add/modify something in this file, you should add same test to Selection_setBaseAndExtent.html too. 72 */ 73 74 75 // Selection.addRange() with collapsed range. 76 test(function() { 77 resetFocusAndSelectionRange(); 78 document.getSelection().removeAllRanges(); 79 var range = document.createRange(); 80 range.setStart(staticBefore.textNode, 0); 81 document.getSelection().addRange(range); 82 assert_equals(document.activeElement, document.body); 83 assert_equals(document.documentElement.scrollTop, 0); 84 }, "Active element should be the <body> after Selection.addRange() with collapsed range at start of the first text node of 'staticBefore' when active element is the <body>"); 85 test(function() { 86 resetFocusAndSelectionRange(); 87 document.getSelection().removeAllRanges(); 88 var range = document.createRange(); 89 range.setStart(editor.textNode, 0); 90 document.getSelection().addRange(range); 91 assert_equals(document.activeElement, editor.element); 92 assert_equals(document.documentElement.scrollTop, 0); 93 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'editor' when active element is the <body>"); 94 test(function() { 95 resetFocusAndSelectionRange(); 96 document.getSelection().removeAllRanges(); 97 var range = document.createRange(); 98 range.setStart(outerEditor.textNode, 0); 99 document.getSelection().addRange(range); 100 assert_equals(document.activeElement, outerEditor.element); 101 assert_equals(document.documentElement.scrollTop, 0); 102 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'outerEditor' when active element is the <body>"); 103 test(function() { 104 resetFocusAndSelectionRange(); 105 document.getSelection().removeAllRanges(); 106 var range = document.createRange(); 107 range.setStart(staticInEditor.textNode, 0); 108 document.getSelection().addRange(range); 109 assert_equals(document.activeElement, document.body); 110 assert_equals(document.documentElement.scrollTop, 0); 111 }, "Active element should be the <body> after Selection.addRange() with collapsed range at start of the first text node of 'staticInEditor' when active element is the <body>"); 112 test(function() { 113 resetFocusAndSelectionRange(); 114 document.getSelection().removeAllRanges(); 115 var range = document.createRange(); 116 range.setStart(innerEditor.textNode, 0); 117 document.getSelection().addRange(range); 118 assert_equals(document.activeElement, innerEditor.element); 119 assert_equals(document.documentElement.scrollTop, 0); 120 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'innerEditor' when active element is the <body>"); 121 test(function() { 122 resetFocusAndSelectionRange(); 123 document.getSelection().removeAllRanges(); 124 var range = document.createRange(); 125 range.setStart(staticAfter.textNode, 0); 126 document.getSelection().addRange(range); 127 assert_equals(document.activeElement, document.body); 128 assert_equals(document.documentElement.scrollTop, 0); 129 }, "Active element should be the <body> after Selection.addRange() with collapsed range at start of the first text node of 'staticAfter' when active element is the <body>"); 130 test(function() { 131 resetFocusAndSelectionRange(); 132 document.getSelection().removeAllRanges(); 133 var range = document.createRange(); 134 range.setStart(anchor.textNode, 0); 135 document.getSelection().addRange(range); 136 assert_equals(document.activeElement, document.body); 137 assert_equals(document.documentElement.scrollTop, 0); 138 }, "Active element should be the <body> after Selection.addRange() with collapsed range at start of the first text node of 'anchor' when active element is the <body>"); 139 140 test(function() { 141 resetFocusAndSelectionRange(editor); 142 document.getSelection().removeAllRanges(); 143 var range = document.createRange(); 144 range.setStart(staticBefore.textNode, 0); 145 document.getSelection().addRange(range); 146 assert_equals(document.activeElement, editor.element); 147 assert_equals(document.documentElement.scrollTop, 0); 148 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'staticBefore' when active element is 'editor'"); 149 test(function() { 150 resetFocusAndSelectionRange(editor); 151 document.getSelection().removeAllRanges(); 152 var range = document.createRange(); 153 range.setStart(editor.textNode, 0); 154 document.getSelection().addRange(range); 155 assert_equals(document.activeElement, editor.element); 156 assert_equals(document.documentElement.scrollTop, 0); 157 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'editor' when active element is 'editor'"); 158 test(function() { 159 resetFocusAndSelectionRange(editor); 160 document.getSelection().removeAllRanges(); 161 var range = document.createRange(); 162 range.setStart(outerEditor.textNode, 0); 163 document.getSelection().addRange(range); 164 assert_equals(document.activeElement, outerEditor.element); 165 assert_equals(document.documentElement.scrollTop, 0); 166 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'outerEditor' when active element is 'editor'"); 167 test(function() { 168 resetFocusAndSelectionRange(editor); 169 document.getSelection().removeAllRanges(); 170 var range = document.createRange(); 171 range.setStart(staticInEditor.textNode, 0); 172 document.getSelection().addRange(range); 173 assert_equals(document.activeElement, editor.element); 174 assert_equals(document.documentElement.scrollTop, 0); 175 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'staticInEditor' when active element is 'editor'"); 176 test(function() { 177 resetFocusAndSelectionRange(editor); 178 document.getSelection().removeAllRanges(); 179 var range = document.createRange(); 180 range.setStart(innerEditor.textNode, 0); 181 document.getSelection().addRange(range); 182 assert_equals(document.activeElement, innerEditor.element); 183 assert_equals(document.documentElement.scrollTop, 0); 184 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'innerEditor' when active element is 'editor'"); 185 test(function() { 186 resetFocusAndSelectionRange(editor); 187 document.getSelection().removeAllRanges(); 188 var range = document.createRange(); 189 range.setStart(staticAfter.textNode, 0); 190 document.getSelection().addRange(range); 191 assert_equals(document.activeElement, editor.element); 192 assert_equals(document.documentElement.scrollTop, 0); 193 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'staticAfter' when active element is 'editor'"); 194 test(function() { 195 resetFocusAndSelectionRange(editor); 196 document.getSelection().removeAllRanges(); 197 var range = document.createRange(); 198 range.setStart(anchor.textNode, 0); 199 document.getSelection().addRange(range); 200 assert_equals(document.activeElement, editor.element); 201 assert_equals(document.documentElement.scrollTop, 0); 202 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'anchor' when active element is 'editor'"); 203 204 test(function() { 205 resetFocusAndSelectionRange(outerEditor); 206 document.getSelection().removeAllRanges(); 207 var range = document.createRange(); 208 range.setStart(staticBefore.textNode, 0); 209 document.getSelection().addRange(range); 210 assert_equals(document.activeElement, outerEditor.element); 211 assert_equals(document.documentElement.scrollTop, 0); 212 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'staticBefore' when active element is 'outerEditor'"); 213 test(function() { 214 resetFocusAndSelectionRange(outerEditor); 215 document.getSelection().removeAllRanges(); 216 var range = document.createRange(); 217 range.setStart(editor.textNode, 0); 218 document.getSelection().addRange(range); 219 assert_equals(document.activeElement, editor.element); 220 assert_equals(document.documentElement.scrollTop, 0); 221 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'editor' when active element is 'outerEditor'"); 222 test(function() { 223 resetFocusAndSelectionRange(outerEditor); 224 document.getSelection().removeAllRanges(); 225 var range = document.createRange(); 226 range.setStart(outerEditor.textNode, 0); 227 document.getSelection().addRange(range); 228 assert_equals(document.activeElement, outerEditor.element); 229 assert_equals(document.documentElement.scrollTop, 0); 230 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'outerEditor' when active element is 'outerEditor'"); 231 test(function() { 232 resetFocusAndSelectionRange(outerEditor); 233 document.getSelection().removeAllRanges(); 234 var range = document.createRange(); 235 range.setStart(staticInEditor.textNode, 0); 236 document.getSelection().addRange(range); 237 assert_equals(document.activeElement, outerEditor.element); 238 assert_equals(document.documentElement.scrollTop, 0); 239 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'staticInEditor' when active element is 'outerEditor'"); 240 test(function() { 241 resetFocusAndSelectionRange(outerEditor); 242 document.getSelection().removeAllRanges(); 243 var range = document.createRange(); 244 range.setStart(innerEditor.textNode, 0); 245 document.getSelection().addRange(range); 246 assert_equals(document.activeElement, innerEditor.element); 247 assert_equals(document.documentElement.scrollTop, 0); 248 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'innerEditor' when active element is 'outerEditor'"); 249 test(function() { 250 resetFocusAndSelectionRange(outerEditor); 251 document.getSelection().removeAllRanges(); 252 var range = document.createRange(); 253 range.setStart(staticAfter.textNode, 0); 254 document.getSelection().addRange(range); 255 assert_equals(document.activeElement, outerEditor.element); 256 assert_equals(document.documentElement.scrollTop, 0); 257 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'staticAfter' when active element is 'outerEditor'"); 258 test(function() { 259 resetFocusAndSelectionRange(outerEditor); 260 document.getSelection().removeAllRanges(); 261 var range = document.createRange(); 262 range.setStart(anchor.textNode, 0); 263 document.getSelection().addRange(range); 264 assert_equals(document.activeElement, outerEditor.element); 265 assert_equals(document.documentElement.scrollTop, 0); 266 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'anchor' when active element is 'outerEditor'"); 267 268 test(function() { 269 resetFocusAndSelectionRange(staticInEditor); 270 document.getSelection().removeAllRanges(); 271 var range = document.createRange(); 272 range.setStart(staticBefore.textNode, 0); 273 document.getSelection().addRange(range); 274 assert_equals(document.activeElement, document.body); 275 assert_equals(document.documentElement.scrollTop, 0); 276 }, "Active element should be the <body> after Selection.addRange() with collapsed range at start of the first text node of 'staticBefore' when active element is the <body> and selection is in 'staticInEditor'"); 277 test(function() { 278 resetFocusAndSelectionRange(staticInEditor); 279 document.getSelection().removeAllRanges(); 280 var range = document.createRange(); 281 range.setStart(editor.textNode, 0); 282 document.getSelection().addRange(range); 283 assert_equals(document.activeElement, editor.element); 284 assert_equals(document.documentElement.scrollTop, 0); 285 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'editor' when active element is the <body> and selection is in 'staticInEditor'"); 286 test(function() { 287 resetFocusAndSelectionRange(staticInEditor); 288 document.getSelection().removeAllRanges(); 289 var range = document.createRange(); 290 range.setStart(outerEditor.textNode, 0); 291 document.getSelection().addRange(range); 292 assert_equals(document.activeElement, outerEditor.element); 293 assert_equals(document.documentElement.scrollTop, 0); 294 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'outerEditor' when active element is the <body> and selection is in 'staticInEditor'"); 295 test(function() { 296 resetFocusAndSelectionRange(staticInEditor); 297 document.getSelection().removeAllRanges(); 298 var range = document.createRange(); 299 range.setStart(staticInEditor.textNode, 0); 300 document.getSelection().addRange(range); 301 assert_equals(document.activeElement, document.body); 302 assert_equals(document.documentElement.scrollTop, 0); 303 }, "Active element should be the <body> after Selection.addRange() with collapsed range at start of the first text node of 'staticInEditor' when active element is the <body> and selection is in 'staticInEditor'"); 304 test(function() { 305 resetFocusAndSelectionRange(staticInEditor); 306 document.getSelection().removeAllRanges(); 307 var range = document.createRange(); 308 range.setStart(innerEditor.textNode, 0); 309 document.getSelection().addRange(range); 310 assert_equals(document.activeElement, innerEditor.element); 311 assert_equals(document.documentElement.scrollTop, 0); 312 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'innerEditor' when active element is the <body> and selection is in 'staticInEditor'"); 313 test(function() { 314 resetFocusAndSelectionRange(staticInEditor); 315 document.getSelection().removeAllRanges(); 316 var range = document.createRange(); 317 range.setStart(staticAfter.textNode, 0); 318 document.getSelection().addRange(range); 319 assert_equals(document.activeElement, document.body); 320 assert_equals(document.documentElement.scrollTop, 0); 321 }, "Active element should be the <body> after Selection.addRange() with collapsed range at start of the first text node of 'staticAfter' when active element is the <body> and selection is in 'staticInEditor'"); 322 test(function() { 323 resetFocusAndSelectionRange(staticInEditor); 324 document.getSelection().removeAllRanges(); 325 var range = document.createRange(); 326 range.setStart(anchor.textNode, 0); 327 document.getSelection().addRange(range); 328 assert_equals(document.activeElement, document.body); 329 assert_equals(document.documentElement.scrollTop, 0); 330 }, "Active element should be the <body> after Selection.addRange() with collapsed range at start of the first text node of 'anchor' when active element is the <body> and selection is in 'staticInEditor'"); 331 332 test(function() { 333 resetFocusAndSelectionRange(innerEditor); 334 document.getSelection().removeAllRanges(); 335 var range = document.createRange(); 336 range.setStart(staticBefore.textNode, 0); 337 document.getSelection().addRange(range); 338 assert_equals(document.activeElement, innerEditor.element); 339 assert_equals(document.documentElement.scrollTop, 0); 340 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'staticBefore' when active element is 'innerEditor'"); 341 test(function() { 342 resetFocusAndSelectionRange(innerEditor); 343 document.getSelection().removeAllRanges(); 344 var range = document.createRange(); 345 range.setStart(editor.textNode, 0); 346 document.getSelection().addRange(range); 347 assert_equals(document.activeElement, editor.element); 348 assert_equals(document.documentElement.scrollTop, 0); 349 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'editor' when active element is 'innerEditor'"); 350 test(function() { 351 resetFocusAndSelectionRange(innerEditor); 352 document.getSelection().removeAllRanges(); 353 var range = document.createRange(); 354 range.setStart(outerEditor.textNode, 0); 355 document.getSelection().addRange(range); 356 assert_equals(document.activeElement, outerEditor.element); 357 assert_equals(document.documentElement.scrollTop, 0); 358 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'outerEditor' when active element is 'innerEditor'"); 359 test(function() { 360 resetFocusAndSelectionRange(innerEditor); 361 document.getSelection().removeAllRanges(); 362 var range = document.createRange(); 363 range.setStart(staticInEditor.textNode, 0); 364 document.getSelection().addRange(range); 365 assert_equals(document.activeElement, innerEditor.element); 366 assert_equals(document.documentElement.scrollTop, 0); 367 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'staticInEditor' when active element is 'innerEditor'"); 368 test(function() { 369 resetFocusAndSelectionRange(innerEditor); 370 document.getSelection().removeAllRanges(); 371 var range = document.createRange(); 372 range.setStart(innerEditor.textNode, 0); 373 document.getSelection().addRange(range); 374 assert_equals(document.activeElement, innerEditor.element); 375 assert_equals(document.documentElement.scrollTop, 0); 376 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'innerEditor' when active element is 'innerEditor'"); 377 test(function() { 378 resetFocusAndSelectionRange(innerEditor); 379 document.getSelection().removeAllRanges(); 380 var range = document.createRange(); 381 range.setStart(staticAfter.textNode, 0); 382 document.getSelection().addRange(range); 383 assert_equals(document.activeElement, innerEditor.element); 384 assert_equals(document.documentElement.scrollTop, 0); 385 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'staticAfter' when active element is 'innerEditor'"); 386 test(function() { 387 resetFocusAndSelectionRange(innerEditor); 388 document.getSelection().removeAllRanges(); 389 var range = document.createRange(); 390 range.setStart(anchor.textNode, 0); 391 document.getSelection().addRange(range); 392 assert_equals(document.activeElement, innerEditor.element); 393 assert_equals(document.documentElement.scrollTop, 0); 394 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'anchor' when active element is 'innerEditor'"); 395 396 test(function() { 397 resetFocusAndSelectionRange(anchor); 398 document.getSelection().removeAllRanges(); 399 var range = document.createRange(); 400 range.setStart(staticBefore.textNode, 0); 401 document.getSelection().addRange(range); 402 assert_equals(document.activeElement, anchor.element); 403 assert_equals(document.documentElement.scrollTop, 0); 404 }, "Active element should be 'anchor' after Selection.addRange() with collapsed range at start of the first text node of 'staticBefore' when active element is 'anchor'"); 405 test(function() { 406 resetFocusAndSelectionRange(anchor); 407 document.getSelection().removeAllRanges(); 408 var range = document.createRange(); 409 range.setStart(editor.textNode, 0); 410 document.getSelection().addRange(range); 411 assert_equals(document.activeElement, editor.element); 412 assert_equals(document.documentElement.scrollTop, 0); 413 }, "Active element should be 'editor' after Selection.addRange() with collapsed range at start of the first text node of 'editor' when active element is 'anchor'"); 414 test(function() { 415 resetFocusAndSelectionRange(anchor); 416 document.getSelection().removeAllRanges(); 417 var range = document.createRange(); 418 range.setStart(outerEditor.textNode, 0); 419 document.getSelection().addRange(range); 420 assert_equals(document.activeElement, outerEditor.element); 421 assert_equals(document.documentElement.scrollTop, 0); 422 }, "Active element should be 'outerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'outerEditor' when active element is 'anchor'"); 423 test(function() { 424 resetFocusAndSelectionRange(anchor); 425 document.getSelection().removeAllRanges(); 426 var range = document.createRange(); 427 range.setStart(staticInEditor.textNode, 0); 428 document.getSelection().addRange(range); 429 assert_equals(document.activeElement, anchor.element); 430 assert_equals(document.documentElement.scrollTop, 0); 431 }, "Active element should be 'anchor' after Selection.addRange() with collapsed range at start of the first text node of 'staticInEditor' when active element is 'anchor'"); 432 test(function() { 433 resetFocusAndSelectionRange(anchor); 434 document.getSelection().removeAllRanges(); 435 var range = document.createRange(); 436 range.setStart(innerEditor.textNode, 0); 437 document.getSelection().addRange(range); 438 assert_equals(document.activeElement, innerEditor.element); 439 assert_equals(document.documentElement.scrollTop, 0); 440 }, "Active element should be 'innerEditor' after Selection.addRange() with collapsed range at start of the first text node of 'innerEditor' when active element is 'anchor'"); 441 test(function() { 442 resetFocusAndSelectionRange(anchor); 443 document.getSelection().removeAllRanges(); 444 var range = document.createRange(); 445 range.setStart(staticAfter.textNode, 0); 446 document.getSelection().addRange(range); 447 assert_equals(document.activeElement, anchor.element); 448 assert_equals(document.documentElement.scrollTop, 0); 449 }, "Active element should be 'anchor' after Selection.addRange() with collapsed range at start of the first text node of 'staticAfter' when active element is 'anchor'"); 450 test(function() { 451 resetFocusAndSelectionRange(anchor); 452 document.getSelection().removeAllRanges(); 453 var range = document.createRange(); 454 range.setStart(anchor.textNode, 0); 455 document.getSelection().addRange(range); 456 assert_equals(document.activeElement, anchor.element); 457 assert_equals(document.documentElement.scrollTop, 0); 458 }, "Active element should be 'anchor' after Selection.addRange() with collapsed range at start of the first text node of 'anchor' when active element is 'anchor'"); 459 460 // Selection.addRange() with non-collapsed range in a node. 461 test(function() { 462 resetFocusAndSelectionRange(); 463 document.getSelection().removeAllRanges(); 464 var range = document.createRange(); 465 range.setStart(staticBefore.textNode, 0); 466 range.setEnd(staticBefore.textNode, staticBefore.textLength); 467 document.getSelection().addRange(range); 468 assert_equals(document.activeElement, document.body); 469 assert_equals(document.documentElement.scrollTop, 0); 470 }, "Active element should be the <body> after Selection.addRange() with a range in the first text node of 'staticBefore' when active element is the <body>"); 471 test(function() { 472 resetFocusAndSelectionRange(); 473 document.getSelection().removeAllRanges(); 474 var range = document.createRange(); 475 range.setStart(editor.textNode, 0); 476 range.setEnd(editor.textNode, editor.textLength); 477 document.getSelection().addRange(range); 478 assert_equals(document.activeElement, editor.element); 479 assert_equals(document.documentElement.scrollTop, 0); 480 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'editor' when active element is the <body>"); 481 test(function() { 482 resetFocusAndSelectionRange(); 483 document.getSelection().removeAllRanges(); 484 var range = document.createRange(); 485 range.setStart(outerEditor.textNode, 0); 486 range.setEnd(outerEditor.textNode, outerEditor.textLength); 487 document.getSelection().addRange(range); 488 assert_equals(document.activeElement, outerEditor.element); 489 assert_equals(document.documentElement.scrollTop, 0); 490 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'outerEditor' when active element is the <body>"); 491 test(function() { 492 resetFocusAndSelectionRange(); 493 document.getSelection().removeAllRanges(); 494 var range = document.createRange(); 495 range.setStart(staticInEditor.textNode, 0); 496 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 497 document.getSelection().addRange(range); 498 assert_equals(document.activeElement, document.body); 499 assert_equals(document.documentElement.scrollTop, 0); 500 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'staticInEditor' when active element is the <body>"); 501 test(function() { 502 resetFocusAndSelectionRange(); 503 document.getSelection().removeAllRanges(); 504 var range = document.createRange(); 505 range.setStart(innerEditor.textNode, 0); 506 range.setEnd(innerEditor.textNode, innerEditor.textLength); 507 document.getSelection().addRange(range); 508 assert_equals(document.activeElement, innerEditor.element); 509 assert_equals(document.documentElement.scrollTop, 0); 510 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'innerEditor' when active element is the <body>"); 511 test(function() { 512 resetFocusAndSelectionRange(); 513 document.getSelection().removeAllRanges(); 514 var range = document.createRange(); 515 range.setStart(staticAfter.textNode, 0); 516 range.setEnd(staticAfter.textNode, staticAfter.textLength); 517 document.getSelection().addRange(range); 518 assert_equals(document.activeElement, document.body); 519 assert_equals(document.documentElement.scrollTop, 0); 520 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'staticAfter' when active element is the <body>"); 521 test(function() { 522 resetFocusAndSelectionRange(); 523 document.getSelection().removeAllRanges(); 524 var range = document.createRange(); 525 range.setStart(anchor.textNode, 0); 526 range.setEnd(anchor.textNode, anchor.textLength); 527 document.getSelection().addRange(range); 528 assert_equals(document.activeElement, document.body); 529 assert_equals(document.documentElement.scrollTop, 0); 530 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'anchor' when active element is the <body>"); 531 532 test(function() { 533 resetFocusAndSelectionRange(editor); 534 document.getSelection().removeAllRanges(); 535 var range = document.createRange(); 536 range.setStart(staticBefore.textNode, 0); 537 range.setEnd(staticBefore.textNode, staticBefore.textLength); 538 document.getSelection().addRange(range); 539 assert_equals(document.activeElement, editor.element); 540 assert_equals(document.documentElement.scrollTop, 0); 541 }, "Active element should be 'editor' after Selection.addRange() with a range in the first text node of 'staticBefore' when active element is 'editor'"); 542 test(function() { 543 resetFocusAndSelectionRange(editor); 544 document.getSelection().removeAllRanges(); 545 var range = document.createRange(); 546 range.setStart(editor.textNode, 0); 547 range.setEnd(editor.textNode, editor.textLength); 548 document.getSelection().addRange(range); 549 assert_equals(document.activeElement, editor.element); 550 assert_equals(document.documentElement.scrollTop, 0); 551 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'editor' when active element is 'editor'"); 552 test(function() { 553 resetFocusAndSelectionRange(editor); 554 document.getSelection().removeAllRanges(); 555 var range = document.createRange(); 556 range.setStart(outerEditor.textNode, 0); 557 range.setEnd(outerEditor.textNode, outerEditor.textLength); 558 document.getSelection().addRange(range); 559 assert_equals(document.activeElement, outerEditor.element); 560 assert_equals(document.documentElement.scrollTop, 0); 561 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'outerEditor' when active element is 'editor'"); 562 test(function() { 563 resetFocusAndSelectionRange(editor); 564 document.getSelection().removeAllRanges(); 565 var range = document.createRange(); 566 range.setStart(staticInEditor.textNode, 0); 567 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 568 document.getSelection().addRange(range); 569 assert_equals(document.activeElement, editor.element); 570 assert_equals(document.documentElement.scrollTop, 0); 571 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'staticInEditor' when active element is 'editor'"); 572 test(function() { 573 resetFocusAndSelectionRange(editor); 574 document.getSelection().removeAllRanges(); 575 var range = document.createRange(); 576 range.setStart(innerEditor.textNode, 0); 577 range.setEnd(innerEditor.textNode, innerEditor.textLength); 578 document.getSelection().addRange(range); 579 assert_equals(document.activeElement, innerEditor.element); 580 assert_equals(document.documentElement.scrollTop, 0); 581 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'innerEditor' when active element is 'editor'"); 582 test(function() { 583 resetFocusAndSelectionRange(editor); 584 document.getSelection().removeAllRanges(); 585 var range = document.createRange(); 586 range.setStart(staticAfter.textNode, 0); 587 range.setEnd(staticAfter.textNode, staticAfter.textLength); 588 document.getSelection().addRange(range); 589 assert_equals(document.activeElement, editor.element); 590 assert_equals(document.documentElement.scrollTop, 0); 591 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'staticAfter' when active element is 'editor'"); 592 test(function() { 593 resetFocusAndSelectionRange(editor); 594 document.getSelection().removeAllRanges(); 595 var range = document.createRange(); 596 range.setStart(anchor.textNode, 0); 597 range.setEnd(anchor.textNode, anchor.textLength); 598 document.getSelection().addRange(range); 599 assert_equals(document.activeElement, editor.element); 600 assert_equals(document.documentElement.scrollTop, 0); 601 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'anchor' when active element is 'editor'"); 602 603 test(function() { 604 resetFocusAndSelectionRange(outerEditor); 605 document.getSelection().removeAllRanges(); 606 var range = document.createRange(); 607 range.setStart(staticBefore.textNode, 0); 608 range.setEnd(staticBefore.textNode, staticBefore.textLength); 609 document.getSelection().addRange(range); 610 assert_equals(document.activeElement, outerEditor.element); 611 assert_equals(document.documentElement.scrollTop, 0); 612 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in the first text node of 'staticBefore' when active element is 'outerEditor'"); 613 test(function() { 614 resetFocusAndSelectionRange(outerEditor); 615 document.getSelection().removeAllRanges(); 616 var range = document.createRange(); 617 range.setStart(editor.textNode, 0); 618 range.setEnd(editor.textNode, editor.textLength); 619 document.getSelection().addRange(range); 620 assert_equals(document.activeElement, editor.element); 621 assert_equals(document.documentElement.scrollTop, 0); 622 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'editor' when active element is 'outerEditor'"); 623 test(function() { 624 resetFocusAndSelectionRange(outerEditor); 625 document.getSelection().removeAllRanges(); 626 var range = document.createRange(); 627 range.setStart(outerEditor.textNode, 0); 628 range.setEnd(outerEditor.textNode, outerEditor.textLength); 629 document.getSelection().addRange(range); 630 assert_equals(document.activeElement, outerEditor.element); 631 assert_equals(document.documentElement.scrollTop, 0); 632 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'outerEditor' when active element is 'outerEditor'"); 633 test(function() { 634 resetFocusAndSelectionRange(outerEditor); 635 document.getSelection().removeAllRanges(); 636 var range = document.createRange(); 637 range.setStart(staticInEditor.textNode, 0); 638 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 639 document.getSelection().addRange(range); 640 assert_equals(document.activeElement, outerEditor.element); 641 assert_equals(document.documentElement.scrollTop, 0); 642 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'staticInEditor' when active element is 'outerEditor'"); 643 test(function() { 644 resetFocusAndSelectionRange(outerEditor); 645 document.getSelection().removeAllRanges(); 646 var range = document.createRange(); 647 range.setStart(innerEditor.textNode, 0); 648 range.setEnd(innerEditor.textNode, innerEditor.textLength); 649 document.getSelection().addRange(range); 650 assert_equals(document.activeElement, innerEditor.element); 651 assert_equals(document.documentElement.scrollTop, 0); 652 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'innerEditor' when active element is 'outerEditor'"); 653 test(function() { 654 resetFocusAndSelectionRange(outerEditor); 655 document.getSelection().removeAllRanges(); 656 var range = document.createRange(); 657 range.setStart(staticAfter.textNode, 0); 658 range.setEnd(staticAfter.textNode, staticAfter.textLength); 659 document.getSelection().addRange(range); 660 assert_equals(document.activeElement, outerEditor.element); 661 assert_equals(document.documentElement.scrollTop, 0); 662 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'staticAfter' when active element is 'outerEditor'"); 663 test(function() { 664 resetFocusAndSelectionRange(outerEditor); 665 document.getSelection().removeAllRanges(); 666 var range = document.createRange(); 667 range.setStart(anchor.textNode, 0); 668 range.setEnd(anchor.textNode, anchor.textLength); 669 document.getSelection().addRange(range); 670 assert_equals(document.activeElement, outerEditor.element); 671 assert_equals(document.documentElement.scrollTop, 0); 672 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'anchor' when active element is 'outerEditor'"); 673 674 test(function() { 675 resetFocusAndSelectionRange(staticInEditor); 676 document.getSelection().removeAllRanges(); 677 var range = document.createRange(); 678 range.setStart(staticBefore.textNode, 0); 679 range.setEnd(staticBefore.textNode, staticBefore.textLength); 680 document.getSelection().addRange(range); 681 assert_equals(document.activeElement, document.body); 682 assert_equals(document.documentElement.scrollTop, 0); 683 }, "Active element should be the <body> after Selection.addRange() with a range in the first text node of 'staticBefore' when active element is 'outerEditor' and selection is in 'staticInEditor'"); 684 test(function() { 685 resetFocusAndSelectionRange(staticInEditor); 686 document.getSelection().removeAllRanges(); 687 var range = document.createRange(); 688 range.setStart(editor.textNode, 0); 689 range.setEnd(editor.textNode, editor.textLength); 690 document.getSelection().addRange(range); 691 assert_equals(document.activeElement, editor.element); 692 assert_equals(document.documentElement.scrollTop, 0); 693 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'editor' when active element is 'outerEditor' and selection is in 'staticInEditor'"); 694 test(function() { 695 resetFocusAndSelectionRange(staticInEditor); 696 document.getSelection().removeAllRanges(); 697 var range = document.createRange(); 698 range.setStart(outerEditor.textNode, 0); 699 range.setEnd(outerEditor.textNode, outerEditor.textLength); 700 document.getSelection().addRange(range); 701 assert_equals(document.activeElement, outerEditor.element); 702 assert_equals(document.documentElement.scrollTop, 0); 703 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'outerEditor' when active element is 'outerEditor' and selection is in 'staticInEditor'"); 704 test(function() { 705 resetFocusAndSelectionRange(staticInEditor); 706 document.getSelection().removeAllRanges(); 707 var range = document.createRange(); 708 range.setStart(staticInEditor.textNode, 0); 709 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 710 document.getSelection().addRange(range); 711 assert_equals(document.activeElement, document.body); 712 assert_equals(document.documentElement.scrollTop, 0); 713 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'staticInEditor' when active element is 'outerEditor' and selection is in 'staticInEditor'"); 714 test(function() { 715 resetFocusAndSelectionRange(staticInEditor); 716 document.getSelection().removeAllRanges(); 717 var range = document.createRange(); 718 range.setStart(innerEditor.textNode, 0); 719 range.setEnd(innerEditor.textNode, innerEditor.textLength); 720 document.getSelection().addRange(range); 721 assert_equals(document.activeElement, innerEditor.element); 722 assert_equals(document.documentElement.scrollTop, 0); 723 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'innerEditor' when active element is 'outerEditor' and selection is in 'staticInEditor'"); 724 test(function() { 725 resetFocusAndSelectionRange(staticInEditor); 726 document.getSelection().removeAllRanges(); 727 var range = document.createRange(); 728 range.setStart(staticAfter.textNode, 0); 729 range.setEnd(staticAfter.textNode, staticAfter.textLength); 730 document.getSelection().addRange(range); 731 assert_equals(document.activeElement, document.body); 732 assert_equals(document.documentElement.scrollTop, 0); 733 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'staticAfter' when active element is 'outerEditor' and selection is in 'staticInEditor'"); 734 test(function() { 735 resetFocusAndSelectionRange(staticInEditor); 736 document.getSelection().removeAllRanges(); 737 var range = document.createRange(); 738 range.setStart(anchor.textNode, 0); 739 range.setEnd(anchor.textNode, anchor.textLength); 740 document.getSelection().addRange(range); 741 assert_equals(document.activeElement, document.body); 742 assert_equals(document.documentElement.scrollTop, 0); 743 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'anchor' when active element is 'outerEditor' and selection is in 'staticInEditor'"); 744 745 test(function() { 746 resetFocusAndSelectionRange(innerEditor); 747 document.getSelection().removeAllRanges(); 748 var range = document.createRange(); 749 range.setStart(staticBefore.textNode, 0); 750 range.setEnd(staticBefore.textNode, staticBefore.textLength); 751 document.getSelection().addRange(range); 752 assert_equals(document.activeElement, innerEditor.element); 753 assert_equals(document.documentElement.scrollTop, 0); 754 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in the first text node of 'staticBefore' when active element is 'innerEditor'"); 755 test(function() { 756 resetFocusAndSelectionRange(innerEditor); 757 document.getSelection().removeAllRanges(); 758 var range = document.createRange(); 759 range.setStart(editor.textNode, 0); 760 range.setEnd(editor.textNode, editor.textLength); 761 document.getSelection().addRange(range); 762 assert_equals(document.activeElement, editor.element); 763 assert_equals(document.documentElement.scrollTop, 0); 764 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'editor' when active element is 'innerEditor'"); 765 test(function() { 766 resetFocusAndSelectionRange(innerEditor); 767 document.getSelection().removeAllRanges(); 768 var range = document.createRange(); 769 range.setStart(outerEditor.textNode, 0); 770 range.setEnd(outerEditor.textNode, outerEditor.textLength); 771 document.getSelection().addRange(range); 772 assert_equals(document.activeElement, outerEditor.element); 773 assert_equals(document.documentElement.scrollTop, 0); 774 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'outerEditor' when active element is 'innerEditor'"); 775 test(function() { 776 resetFocusAndSelectionRange(innerEditor); 777 document.getSelection().removeAllRanges(); 778 var range = document.createRange(); 779 range.setStart(staticInEditor.textNode, 0); 780 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 781 document.getSelection().addRange(range); 782 assert_equals(document.activeElement, innerEditor.element); 783 assert_equals(document.documentElement.scrollTop, 0); 784 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'staticInEditor' when active element is 'innerEditor'"); 785 test(function() { 786 resetFocusAndSelectionRange(innerEditor); 787 document.getSelection().removeAllRanges(); 788 var range = document.createRange(); 789 range.setStart(innerEditor.textNode, 0); 790 range.setEnd(innerEditor.textNode, innerEditor.textLength); 791 document.getSelection().addRange(range); 792 assert_equals(document.activeElement, innerEditor.element); 793 assert_equals(document.documentElement.scrollTop, 0); 794 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'innerEditor' when active element is 'innerEditor'"); 795 test(function() { 796 resetFocusAndSelectionRange(innerEditor); 797 document.getSelection().removeAllRanges(); 798 var range = document.createRange(); 799 range.setStart(staticAfter.textNode, 0); 800 range.setEnd(staticAfter.textNode, staticAfter.textLength); 801 document.getSelection().addRange(range); 802 assert_equals(document.activeElement, innerEditor.element); 803 assert_equals(document.documentElement.scrollTop, 0); 804 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'staticAfter' when active element is 'innerEditor'"); 805 test(function() { 806 resetFocusAndSelectionRange(innerEditor); 807 document.getSelection().removeAllRanges(); 808 var range = document.createRange(); 809 range.setStart(anchor.textNode, 0); 810 range.setEnd(anchor.textNode, anchor.textLength); 811 document.getSelection().addRange(range); 812 assert_equals(document.activeElement, innerEditor.element); 813 assert_equals(document.documentElement.scrollTop, 0); 814 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'anchor' when active element is 'innerEditor'"); 815 816 test(function() { 817 resetFocusAndSelectionRange(anchor); 818 document.getSelection().removeAllRanges(); 819 var range = document.createRange(); 820 range.setStart(staticBefore.textNode, 0); 821 range.setEnd(staticBefore.textNode, staticBefore.textLength); 822 document.getSelection().addRange(range); 823 assert_equals(document.activeElement, anchor.element); 824 assert_equals(document.documentElement.scrollTop, 0); 825 }, "Active element should be the <body> after Selection.addRange() with a range in the first text node of 'staticBefore' when active element is 'anchor'"); 826 test(function() { 827 resetFocusAndSelectionRange(anchor); 828 document.getSelection().removeAllRanges(); 829 var range = document.createRange(); 830 range.setStart(editor.textNode, 0); 831 range.setEnd(editor.textNode, editor.textLength); 832 document.getSelection().addRange(range); 833 assert_equals(document.activeElement, editor.element); 834 assert_equals(document.documentElement.scrollTop, 0); 835 }, "Active element should be 'editor' after Selection.addRange() with a range in start of the first text node of 'editor' when active element is 'anchor'"); 836 test(function() { 837 resetFocusAndSelectionRange(anchor); 838 document.getSelection().removeAllRanges(); 839 var range = document.createRange(); 840 range.setStart(outerEditor.textNode, 0); 841 range.setEnd(outerEditor.textNode, outerEditor.textLength); 842 document.getSelection().addRange(range); 843 assert_equals(document.activeElement, outerEditor.element); 844 assert_equals(document.documentElement.scrollTop, 0); 845 }, "Active element should be 'outerEditor' after Selection.addRange() with a range in start of the first text node of 'outerEditor' when active element is 'anchor'"); 846 test(function() { 847 resetFocusAndSelectionRange(anchor); 848 document.getSelection().removeAllRanges(); 849 var range = document.createRange(); 850 range.setStart(staticInEditor.textNode, 0); 851 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 852 document.getSelection().addRange(range); 853 assert_equals(document.activeElement, anchor.element); 854 assert_equals(document.documentElement.scrollTop, 0); 855 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'staticInEditor' when active element is 'anchor'"); 856 test(function() { 857 resetFocusAndSelectionRange(anchor); 858 document.getSelection().removeAllRanges(); 859 var range = document.createRange(); 860 range.setStart(innerEditor.textNode, 0); 861 range.setEnd(innerEditor.textNode, innerEditor.textLength); 862 document.getSelection().addRange(range); 863 assert_equals(document.activeElement, innerEditor.element); 864 assert_equals(document.documentElement.scrollTop, 0); 865 }, "Active element should be 'innerEditor' after Selection.addRange() with a range in start of the first text node of 'innerEditor' when active element is 'anchor'"); 866 test(function() { 867 resetFocusAndSelectionRange(anchor); 868 document.getSelection().removeAllRanges(); 869 var range = document.createRange(); 870 range.setStart(staticAfter.textNode, 0); 871 range.setEnd(staticAfter.textNode, staticAfter.textLength); 872 document.getSelection().addRange(range); 873 assert_equals(document.activeElement, anchor.element); 874 assert_equals(document.documentElement.scrollTop, 0); 875 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'staticAfter' when active element is 'anchor'"); 876 test(function() { 877 resetFocusAndSelectionRange(anchor); 878 document.getSelection().removeAllRanges(); 879 var range = document.createRange(); 880 range.setStart(anchor.textNode, 0); 881 range.setEnd(anchor.textNode, anchor.textLength); 882 document.getSelection().addRange(range); 883 assert_equals(document.activeElement, anchor.element); 884 assert_equals(document.documentElement.scrollTop, 0); 885 }, "Active element should be the <body> after Selection.addRange() with a range in start of the first text node of 'anchor' when active element is 'anchor'"); 886 887 // Selection.addRange() with a range across editing host boundary. 888 test(function() { 889 resetFocusAndSelectionRange(); 890 document.getSelection().removeAllRanges(); 891 var range = document.createRange(); 892 range.setStart(staticBefore.textNode, 0); 893 range.setEnd(editor.textNode, editor.textLength); 894 document.getSelection().addRange(range); 895 assert_equals(document.activeElement, document.body); 896 assert_equals(document.documentElement.scrollTop, 0); 897 }, "Active element should be the <body> after Selection.addRange() with a range between start of the first text node of 'staticBefore' and end of the first text node of 'editor' (no common editing host) when active element is the <body>"); 898 test(function() { 899 resetFocusAndSelectionRange(); 900 document.getSelection().removeAllRanges(); 901 var range = document.createRange(); 902 range.setStart(editor.textNode, 0); 903 range.setEnd(outerEditor.textNode, outerEditor.textLength); 904 document.getSelection().addRange(range); 905 assert_equals(document.activeElement, document.body); 906 assert_equals(document.documentElement.scrollTop, 0); 907 }, "Active element should be the <body> after Selection.addRange() with a range between start of the first text node of 'editor' and end of the first text node of 'outerEditor' (no common editing host) when active element is the <body>"); 908 test(function() { 909 resetFocusAndSelectionRange(); 910 document.getSelection().removeAllRanges(); 911 var range = document.createRange(); 912 range.setStart(outerEditor.textNode, 0); 913 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 914 document.getSelection().addRange(range); 915 assert_equals(document.activeElement, outerEditor.element); 916 assert_equals(document.documentElement.scrollTop, 0); 917 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'staticInEditor' (common editing host is outerEditor) when active element is the <body>"); 918 test(function() { 919 resetFocusAndSelectionRange(); 920 document.getSelection().removeAllRanges(); 921 var range = document.createRange(); 922 range.setStart(staticInEditor.textNode, 0); 923 range.setEnd(innerEditor.textNode, innerEditor.textLength); 924 document.getSelection().addRange(range); 925 assert_equals(document.activeElement, document.body); 926 assert_equals(document.documentElement.scrollTop, 0); 927 }, "Active element should be the <body> after Selection.addRange() with a range between start of the first text node of 'staticInEditor' and end of the first text node of 'innerEditor' (no common editing host) when active element is the <body>"); 928 test(function() { 929 resetFocusAndSelectionRange(); 930 document.getSelection().removeAllRanges(); 931 var range = document.createRange(); 932 range.setStart(outerEditor.textNode, 0); 933 range.setEnd(innerEditor.textNode, innerEditor.textLength); 934 document.getSelection().addRange(range); 935 assert_equals(document.activeElement, outerEditor.element); 936 assert_equals(document.documentElement.scrollTop, 0); 937 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'innerEditor' (common editing host is outerEditor) when active element is the <body>"); 938 test(function() { 939 resetFocusAndSelectionRange(); 940 document.getSelection().removeAllRanges(); 941 var range = document.createRange(); 942 range.setStart(innerEditor.textNode, 0); 943 range.setEnd(staticAfter.textNode, staticAfter.textLength); 944 document.getSelection().addRange(range); 945 assert_equals(document.activeElement, document.body); 946 assert_equals(document.documentElement.scrollTop, 0); 947 }, "Active element should be the <body> after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'staticAfter' (no common editing host) when active element is the <body>"); 948 test(function() { 949 resetFocusAndSelectionRange(); 950 document.getSelection().removeAllRanges(); 951 var range = document.createRange(); 952 range.setStart(innerEditor.textNode, 0); 953 range.setEnd(anchor.textNode, anchor.textLength); 954 document.getSelection().addRange(range); 955 assert_equals(document.activeElement, document.body); 956 assert_equals(document.documentElement.scrollTop, 0); 957 }, "Active element should be the <body> after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'anchor' (no common editing host) when active element is the <body>"); 958 959 test(function() { 960 resetFocusAndSelectionRange(editor); 961 document.getSelection().removeAllRanges(); 962 var range = document.createRange(); 963 range.setStart(staticBefore.textNode, 0); 964 range.setEnd(editor.textNode, editor.textLength); 965 document.getSelection().addRange(range); 966 assert_equals(document.activeElement, editor.element); 967 assert_equals(document.documentElement.scrollTop, 0); 968 }, "Active element should be 'editor' after Selection.addRange() with a range between start of the first text node of 'staticBefore' and end of the first text node of 'editor' (no common editing host) when active element is 'editor'"); 969 test(function() { 970 resetFocusAndSelectionRange(editor); 971 document.getSelection().removeAllRanges(); 972 var range = document.createRange(); 973 range.setStart(editor.textNode, 0); 974 range.setEnd(outerEditor.textNode, outerEditor.textLength); 975 document.getSelection().addRange(range); 976 assert_equals(document.activeElement, editor.element); 977 assert_equals(document.documentElement.scrollTop, 0); 978 }, "Active element should be 'editor' after Selection.addRange() with a range between start of the first text node of 'editor' and end of the first text node of 'outerEditor' (no common editing host) when active element is 'editor'"); 979 test(function() { 980 resetFocusAndSelectionRange(editor); 981 document.getSelection().removeAllRanges(); 982 var range = document.createRange(); 983 range.setStart(outerEditor.textNode, 0); 984 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 985 document.getSelection().addRange(range); 986 assert_equals(document.activeElement, outerEditor.element); 987 assert_equals(document.documentElement.scrollTop, 0); 988 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'staticInEditor' (common editing host is outerEditor) when active element is 'editor'"); 989 test(function() { 990 resetFocusAndSelectionRange(editor); 991 document.getSelection().removeAllRanges(); 992 var range = document.createRange(); 993 range.setStart(staticInEditor.textNode, 0); 994 range.setEnd(innerEditor.textNode, innerEditor.textLength); 995 document.getSelection().addRange(range); 996 assert_equals(document.activeElement, editor.element); 997 assert_equals(document.documentElement.scrollTop, 0); 998 }, "Active element should be 'editor' after Selection.addRange() with a range between start of the first text node of 'staticInEditor' and end of the first text node of 'innerEditor' (no common editing host) when active element is 'editor'"); 999 test(function() { 1000 resetFocusAndSelectionRange(editor); 1001 document.getSelection().removeAllRanges(); 1002 var range = document.createRange(); 1003 range.setStart(outerEditor.textNode, 0); 1004 range.setEnd(innerEditor.textNode, innerEditor.textLength); 1005 document.getSelection().addRange(range); 1006 assert_equals(document.activeElement, outerEditor.element); 1007 assert_equals(document.documentElement.scrollTop, 0); 1008 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'innerEditor' (common editing host is outerEditor) when active element is 'editor'"); 1009 test(function() { 1010 resetFocusAndSelectionRange(editor); 1011 document.getSelection().removeAllRanges(); 1012 var range = document.createRange(); 1013 range.setStart(innerEditor.textNode, 0); 1014 range.setEnd(staticAfter.textNode, staticAfter.textLength); 1015 document.getSelection().addRange(range); 1016 assert_equals(document.activeElement, editor.element); 1017 assert_equals(document.documentElement.scrollTop, 0); 1018 }, "Active element should be 'editor' after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'staticAfter' (no common editing host) when active element is 'editor'"); 1019 test(function() { 1020 resetFocusAndSelectionRange(editor); 1021 document.getSelection().removeAllRanges(); 1022 var range = document.createRange(); 1023 range.setStart(innerEditor.textNode, 0); 1024 range.setEnd(anchor.textNode, anchor.textLength); 1025 document.getSelection().addRange(range); 1026 assert_equals(document.activeElement, editor.element); 1027 assert_equals(document.documentElement.scrollTop, 0); 1028 }, "Active element should be 'editor' after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'anchor' (no common editing host) when active element is 'editor'"); 1029 1030 test(function() { 1031 resetFocusAndSelectionRange(outerEditor); 1032 document.getSelection().removeAllRanges(); 1033 var range = document.createRange(); 1034 range.setStart(staticBefore.textNode, 0); 1035 range.setEnd(editor.textNode, editor.textLength); 1036 document.getSelection().addRange(range); 1037 assert_equals(document.activeElement, outerEditor.element); 1038 assert_equals(document.documentElement.scrollTop, 0); 1039 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'staticBefore' and end of the first text node of 'editor' (no common editing host) when active element is 'outerEditor'"); 1040 test(function() { 1041 resetFocusAndSelectionRange(outerEditor); 1042 document.getSelection().removeAllRanges(); 1043 var range = document.createRange(); 1044 range.setStart(editor.textNode, 0); 1045 range.setEnd(outerEditor.textNode, outerEditor.textLength); 1046 document.getSelection().addRange(range); 1047 assert_equals(document.activeElement, outerEditor.element); 1048 assert_equals(document.documentElement.scrollTop, 0); 1049 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'editor' and end of the first text node of 'outerEditor' (no common editing host) when active element is 'outerEditor'"); 1050 test(function() { 1051 resetFocusAndSelectionRange(outerEditor); 1052 document.getSelection().removeAllRanges(); 1053 var range = document.createRange(); 1054 range.setStart(outerEditor.textNode, 0); 1055 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 1056 document.getSelection().addRange(range); 1057 assert_equals(document.activeElement, outerEditor.element); 1058 assert_equals(document.documentElement.scrollTop, 0); 1059 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'staticInEditor' (common editing host is outerEditor) when active element is 'outerEditor'"); 1060 test(function() { 1061 resetFocusAndSelectionRange(outerEditor); 1062 document.getSelection().removeAllRanges(); 1063 var range = document.createRange(); 1064 range.setStart(staticInEditor.textNode, 0); 1065 range.setEnd(innerEditor.textNode, innerEditor.textLength); 1066 document.getSelection().addRange(range); 1067 assert_equals(document.activeElement, outerEditor.element); 1068 assert_equals(document.documentElement.scrollTop, 0); 1069 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'staticInEditor' and end of the first text node of 'innerEditor' (no common editing host) when active element is 'outerEditor'"); 1070 test(function() { 1071 resetFocusAndSelectionRange(outerEditor); 1072 document.getSelection().removeAllRanges(); 1073 var range = document.createRange(); 1074 range.setStart(outerEditor.textNode, 0); 1075 range.setEnd(innerEditor.textNode, innerEditor.textLength); 1076 document.getSelection().addRange(range); 1077 assert_equals(document.activeElement, outerEditor.element); 1078 assert_equals(document.documentElement.scrollTop, 0); 1079 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'innerEditor' (common editing host is outerEditor) when active element is 'outerEditor'"); 1080 test(function() { 1081 resetFocusAndSelectionRange(outerEditor); 1082 document.getSelection().removeAllRanges(); 1083 var range = document.createRange(); 1084 range.setStart(innerEditor.textNode, 0); 1085 range.setEnd(staticAfter.textNode, staticAfter.textLength); 1086 document.getSelection().addRange(range); 1087 assert_equals(document.activeElement, outerEditor.element); 1088 assert_equals(document.documentElement.scrollTop, 0); 1089 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'staticAfter' (no common editing host) when active element is 'outerEditor'"); 1090 test(function() { 1091 resetFocusAndSelectionRange(outerEditor); 1092 document.getSelection().removeAllRanges(); 1093 var range = document.createRange(); 1094 range.setStart(innerEditor.textNode, 0); 1095 range.setEnd(anchor.textNode, anchor.textLength); 1096 document.getSelection().addRange(range); 1097 assert_equals(document.activeElement, outerEditor.element); 1098 assert_equals(document.documentElement.scrollTop, 0); 1099 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'anchor' (no common editing host) when active element is 'outerEditor'"); 1100 1101 test(function() { 1102 resetFocusAndSelectionRange(innerEditor); 1103 document.getSelection().removeAllRanges(); 1104 var range = document.createRange(); 1105 range.setStart(staticBefore.textNode, 0); 1106 range.setEnd(editor.textNode, editor.textLength); 1107 document.getSelection().addRange(range); 1108 assert_equals(document.activeElement, innerEditor.element); 1109 assert_equals(document.documentElement.scrollTop, 0); 1110 }, "Active element should be 'innerEditor' after Selection.addRange() with a range between start of the first text node of 'staticBefore' and end of the first text node of 'editor' (no common editing host) when active element is 'innerEditor'"); 1111 test(function() { 1112 resetFocusAndSelectionRange(innerEditor); 1113 document.getSelection().removeAllRanges(); 1114 var range = document.createRange(); 1115 range.setStart(editor.textNode, 0); 1116 range.setEnd(outerEditor.textNode, outerEditor.textLength); 1117 document.getSelection().addRange(range); 1118 assert_equals(document.activeElement, innerEditor.element); 1119 assert_equals(document.documentElement.scrollTop, 0); 1120 }, "Active element should be 'innerEditor' after Selection.addRange() with a range between start of the first text node of 'editor' and end of the first text node of 'outerEditor' (no common editing host) when active element is 'innerEditor'"); 1121 test(function() { 1122 resetFocusAndSelectionRange(innerEditor); 1123 document.getSelection().removeAllRanges(); 1124 var range = document.createRange(); 1125 range.setStart(outerEditor.textNode, 0); 1126 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 1127 document.getSelection().addRange(range); 1128 assert_equals(document.activeElement, outerEditor.element); 1129 assert_equals(document.documentElement.scrollTop, 0); 1130 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'staticInEditor' (common editing host is outerEditor) when active element is 'innerEditor'"); 1131 test(function() { 1132 resetFocusAndSelectionRange(innerEditor); 1133 document.getSelection().removeAllRanges(); 1134 var range = document.createRange(); 1135 range.setStart(staticInEditor.textNode, 0); 1136 range.setEnd(innerEditor.textNode, innerEditor.textLength); 1137 document.getSelection().addRange(range); 1138 assert_equals(document.activeElement, innerEditor.element); 1139 assert_equals(document.documentElement.scrollTop, 0); 1140 }, "Active element should be 'innerEditor' after Selection.addRange() with a range between start of the first text node of 'staticInEditor' and end of the first text node of 'innerEditor' (no common editing host) when active element is 'innerEditor'"); 1141 test(function() { 1142 resetFocusAndSelectionRange(innerEditor); 1143 document.getSelection().removeAllRanges(); 1144 var range = document.createRange(); 1145 range.setStart(outerEditor.textNode, 0); 1146 range.setEnd(innerEditor.textNode, innerEditor.textLength); 1147 document.getSelection().addRange(range); 1148 assert_equals(document.activeElement, outerEditor.element); 1149 assert_equals(document.documentElement.scrollTop, 0); 1150 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'innerEditor' (common editing host is outerEditor) when active element is 'innerEditor'"); 1151 test(function() { 1152 resetFocusAndSelectionRange(innerEditor); 1153 document.getSelection().removeAllRanges(); 1154 var range = document.createRange(); 1155 range.setStart(innerEditor.textNode, 0); 1156 range.setEnd(staticAfter.textNode, staticAfter.textLength); 1157 document.getSelection().addRange(range); 1158 assert_equals(document.activeElement, innerEditor.element); 1159 assert_equals(document.documentElement.scrollTop, 0); 1160 }, "Active element should be 'innerEditor' after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'staticAfter' (no common editing host) when active element is 'innerEditor'"); 1161 test(function() { 1162 resetFocusAndSelectionRange(innerEditor); 1163 document.getSelection().removeAllRanges(); 1164 var range = document.createRange(); 1165 range.setStart(innerEditor.textNode, 0); 1166 range.setEnd(anchor.textNode, anchor.textLength); 1167 document.getSelection().addRange(range); 1168 assert_equals(document.activeElement, innerEditor.element); 1169 assert_equals(document.documentElement.scrollTop, 0); 1170 }, "Active element should be 'innerEditor' after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'anchor' (no common editing host) when active element is 'innerEditor'"); 1171 1172 test(function() { 1173 resetFocusAndSelectionRange(anchor); 1174 document.getSelection().removeAllRanges(); 1175 var range = document.createRange(); 1176 range.setStart(staticBefore.textNode, 0); 1177 range.setEnd(editor.textNode, editor.textLength); 1178 document.getSelection().addRange(range); 1179 assert_equals(document.activeElement, anchor.element); 1180 assert_equals(document.documentElement.scrollTop, 0); 1181 }, "Active element should be 'anchor' after Selection.addRange() with a range between start of the first text node of 'staticBefore' and end of the first text node of 'editor' (no common editing host) when active element is 'anchor'"); 1182 test(function() { 1183 resetFocusAndSelectionRange(anchor); 1184 document.getSelection().removeAllRanges(); 1185 var range = document.createRange(); 1186 range.setStart(editor.textNode, 0); 1187 range.setEnd(outerEditor.textNode, outerEditor.textLength); 1188 document.getSelection().addRange(range); 1189 assert_equals(document.activeElement, anchor.element); 1190 assert_equals(document.documentElement.scrollTop, 0); 1191 }, "Active element should be 'anchor' after Selection.addRange() with a range between start of the first text node of 'editor' and end of the first text node of 'outerEditor' (no common editing host) when active element is 'anchor'"); 1192 test(function() { 1193 resetFocusAndSelectionRange(anchor); 1194 document.getSelection().removeAllRanges(); 1195 var range = document.createRange(); 1196 range.setStart(outerEditor.textNode, 0); 1197 range.setEnd(staticInEditor.textNode, staticInEditor.textLength); 1198 document.getSelection().addRange(range); 1199 assert_equals(document.activeElement, outerEditor.element); 1200 assert_equals(document.documentElement.scrollTop, 0); 1201 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'staticInEditor' (common editing host is outerEditor) when active element is 'anchor'"); 1202 test(function() { 1203 resetFocusAndSelectionRange(anchor); 1204 document.getSelection().removeAllRanges(); 1205 var range = document.createRange(); 1206 range.setStart(staticInEditor.textNode, 0); 1207 range.setEnd(innerEditor.textNode, innerEditor.textLength); 1208 document.getSelection().addRange(range); 1209 assert_equals(document.activeElement, anchor.element); 1210 assert_equals(document.documentElement.scrollTop, 0); 1211 }, "Active element should be 'anchor' after Selection.addRange() with a range between start of the first text node of 'staticInEditor' and end of the first text node of 'innerEditor' (no common editing host) when active element is 'anchor'"); 1212 test(function() { 1213 resetFocusAndSelectionRange(anchor); 1214 document.getSelection().removeAllRanges(); 1215 var range = document.createRange(); 1216 range.setStart(outerEditor.textNode, 0); 1217 range.setEnd(innerEditor.textNode, innerEditor.textLength); 1218 document.getSelection().addRange(range); 1219 assert_equals(document.activeElement, outerEditor.element); 1220 assert_equals(document.documentElement.scrollTop, 0); 1221 }, "Active element should be 'outerEditor' after Selection.addRange() with a range between start of the first text node of 'outerEditor' and end of the first text node of 'innerEditor' (common editing host is outerEditor) when active element is 'anchor'"); 1222 test(function() { 1223 resetFocusAndSelectionRange(anchor); 1224 document.getSelection().removeAllRanges(); 1225 var range = document.createRange(); 1226 range.setStart(innerEditor.textNode, 0); 1227 range.setEnd(staticAfter.textNode, staticAfter.textLength); 1228 document.getSelection().addRange(range); 1229 assert_equals(document.activeElement, anchor.element); 1230 assert_equals(document.documentElement.scrollTop, 0); 1231 }, "Active element should be 'anchor' after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'staticAfter' (no common editing host) when active element is 'anchor'"); 1232 test(function() { 1233 resetFocusAndSelectionRange(anchor); 1234 document.getSelection().removeAllRanges(); 1235 var range = document.createRange(); 1236 range.setStart(innerEditor.textNode, 0); 1237 range.setEnd(anchor.textNode, anchor.textLength); 1238 document.getSelection().addRange(range); 1239 assert_equals(document.activeElement, anchor.element); 1240 assert_equals(document.documentElement.scrollTop, 0); 1241 }, "Active element should be 'anchor' after Selection.addRange() with a range between start of the first text node of 'innerEditor' and end of the first text node of 'anchor' (no common editing host) when active element is 'anchor'"); 1242 </script>