OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <p>abcdef</p> |
| 5 <script> |
| 6 test(() => { |
| 7 let selection = getSelection(); |
| 8 selection.removeAllRanges(); |
| 9 let range = document.createRange(); |
| 10 let text = document.querySelector('p').firstChild; |
| 11 range.setStart(text, 1); |
| 12 range.setEnd(text, 2); |
| 13 |
| 14 selection.addRange(range); |
| 15 assert_equals(selection.anchorNode, text); |
| 16 assert_equals(selection.anchorOffset, 1); |
| 17 assert_equals(selection.focusNode, text); |
| 18 assert_equals(selection.focusOffset, 2); |
| 19 |
| 20 range.setStart(text, 0); |
| 21 assert_equals(selection.anchorOffset, 0); |
| 22 }, 'Mutation of Range after adding it to Selection should update Selection attri
butes.'); |
| 23 |
| 24 test(() => { |
| 25 let selection = getSelection(); |
| 26 selection.removeAllRanges(); |
| 27 let range = document.createRange(); |
| 28 range.selectNode(document.body); |
| 29 selection.addRange(range); |
| 30 assert_equals(selection.rangeCount, 1); |
| 31 |
| 32 let document2 = document.implementation.createHTMLDocument(); |
| 33 document2.innerHTML = '<html><body>abc</body></html>'; |
| 34 range.selectNode(document2.body); |
| 35 // TODO(tkent): The specification says nothing about such case. For now, we |
| 36 // unregister the Range from the Selection for ease of implementation |
| 37 // though Firefox and Edge keep |selection.getRangeAt(0) == range|. |
| 38 assert_equals(selection.rangeCount, 0); |
| 39 }, 'Switching Range document should clear registered Selection.'); |
| 40 |
| 41 test(() => { |
| 42 let selection = getSelection(); |
| 43 selection.removeAllRanges(); |
| 44 let range = document.createRange(); |
| 45 range.selectNode(document.body); |
| 46 selection.addRange(range); |
| 47 assert_equals(selection.rangeCount, 1); |
| 48 |
| 49 let span = document.createElement('span'); |
| 50 span.innerHTML = 'text'; |
| 51 range.selectNode(span.firstChild); |
| 52 // TODO(tkent): The specification says nothing about such case. For now, we |
| 53 // unregister the Range from the Selection for ease of implementation |
| 54 // though Firefox and Edge keep |selection.getRangeAt(0) == range|. |
| 55 assert_equals(selection.rangeCount, 0); |
| 56 }, 'Updating Range for another root should clear registered Selection.'); |
| 57 </script> |
OLD | NEW |