anchor-removal.html (2037B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src='/resources/testharness.js'></script> 5 <script src='/resources/testharnessreport.js'></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-actions.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 </head> 10 11 <body> 12 </body> 13 14 <script> 15 async function select_range(t, anchorNode, focusNode) { 16 await new test_driver.Actions() 17 .pointerMove(0, 0, {origin: anchorNode}) 18 .pointerDown() 19 .pointerMove(focusNode.clientWidth, focusNode.clientHeight, {origin: focusNode}) 20 .pointerUp() 21 .send(); 22 } 23 24 const kHTML = ` 25 <div id=parentDiv> 26 <span id=parentParagraph>Parent paragraph</span> 27 <div id=childDiv> 28 <span id=childParagraph1>Child paragraph one</span> 29 <span id=childParagraph2>Paragraph two</span> 30 </div> 31 </div> 32 `; 33 34 // The two tests below are semantically identical, however after the selection 35 // is made but before `remove()`: 36 // - The first test does nothing 37 // - The second test runs asserts on `getSelection()` (before `remove()` is 38 // run). 39 // 40 // The existence of the `getSelection()` asserts before `remove()` appears to 41 // have a side-effect in Chromium browsers. See https://crbug.com/379275917. 42 promise_test(async t => { 43 document.body.innerHTML = kHTML; 44 getSelection().removeAllRanges(); 45 await select_range(t, parentParagraph, childParagraph1); 46 47 parentParagraph.remove(); 48 assert_equals(getSelection().anchorNode, parentDiv, "anchorNode snaps up to parent"); 49 }, "anchorNode snaps up to parent when removed (no asserts)"); 50 51 promise_test(async t => { 52 document.body.innerHTML = kHTML; 53 getSelection().removeAllRanges(); 54 await select_range(t, parentParagraph, childParagraph1); 55 56 assert_equals(getSelection().anchorNode, parentParagraph.firstChild, "anchorNode before move"); 57 parentParagraph.remove(); 58 assert_equals(getSelection().anchorNode, parentDiv, "anchorNode snaps up to parent"); 59 }, "anchorNode snaps up to parent when removed (with asserts)"); 60 </script>