selectall-without-focus.html (2785B)
1 <!DOCTYPE HTML> 2 <head> 3 <meta charset=utf-8> 4 <title>Select All without focus should select not select only in the editing host</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script> 8 "use strict"; 9 10 addEventListener("DOMContentLoaded", () => { 11 test(() => { 12 document.head.remove(); 13 document.execCommand("selectAll"); 14 assert_false( 15 getSelection().isCollapsed, 16 'Selection should not be collapsed after calling document.execCommand("selectAll")' 17 ); 18 const rangeText = getSelection().toString(); 19 assert_true( 20 rangeText.includes("preceding text"), 21 "Selection should contain the preceding text of the editing host" 22 ); 23 assert_true( 24 rangeText.includes("editable text"), 25 "Selection should contain the editable text in the editing host" 26 ); 27 getSelection().removeAllRanges(); 28 }, "execCommand('selectAll') should select all content in the document even if the document body ends with editable content"); 29 30 test(() => { 31 document.querySelector("p").innerHTML = "preceding text <input value='input value'>"; 32 getSelection().collapse(document.querySelector("input"), 0); 33 document.execCommand("selectAll"); 34 assert_false( 35 getSelection().isCollapsed, 36 'Selection should not be collapsed after calling document.execCommand("selectAll")' 37 ); 38 const rangeText = getSelection().toString(); 39 assert_true( 40 rangeText.includes("preceding text"), 41 "Selection should contain the preceding text of the editing host" 42 ); 43 assert_true( 44 rangeText.includes("editable text"), 45 "Selection should contain the editable text in the editing host" 46 ); 47 getSelection().removeAllRanges(); 48 }, "execCommand('selectAll') should select all content in the document when selection is in <input>"); 49 50 test(() => { 51 document.querySelector("p").innerHTML = "preceding text <textarea>textarea value</textarea>"; 52 getSelection().collapse(document.querySelector("textarea"), 0); 53 document.execCommand("selectAll"); 54 assert_false( 55 getSelection().isCollapsed, 56 'Selection should not be collapsed after calling document.execCommand("selectAll")' 57 ); 58 const rangeText = getSelection().toString(); 59 assert_true( 60 rangeText.includes("preceding text"), 61 "Selection should contain the preceding text of the editing host" 62 ); 63 assert_true( 64 rangeText.includes("editable text"), 65 "Selection should contain the editable text in the editing host" 66 ); 67 getSelection().removeAllRanges(); 68 }, "execCommand('selectAll') should select all content in the document when selection is in <textarea>"); 69 }); 70 </script> 71 </head> 72 <p>preceding text</p> 73 <div contenteditable>editable text