indent-preserving-selection.tentative.html (2887B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta chareset="utf-8"> 5 <meta name="timeout" content="long"> 6 <meta name="variant" content="?styleWithCSS=false"> 7 <meta name="variant" content="?styleWithCSS=true"> 8 <title>Test preserving selection after indent</title> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script src="/resources/testdriver.js"></script> 12 <script src="/resources/testdriver-vendor.js"></script> 13 <script src="/resources/testdriver-actions.js"></script> 14 <script src="../include/editor-test-utils.js"></script> 15 </head> 16 <body> 17 <div contenteditable></div> 18 <script> 19 "use strict"; 20 21 const editor = document.querySelector("div[contenteditable]"); 22 const utils = new EditorTestUtils(editor); 23 const styleWithCSS = 24 new URLSearchParams(document.location.search).get("styleWithCSS"); 25 document.execCommand("styleWithCSS", false, styleWithCSS); 26 27 // Note that it's not scope of this test how browsers to indent the selected 28 // content. 29 30 // html: Initial HTML which will be set editor.innerHTML, it should contain 31 // selection range with a pair of "[" or "{" and "]" or "}". 32 // expectedSelectedString: After executing "indent", compared with 33 // getSelection().toString().replace(/[ \n\r]+/g, "") 34 const tests = [ 35 { 36 html: "<div>a[b]c</div>", 37 expectedSelectedString: "b", 38 }, 39 { 40 html: "<div>a[bc</div><div>de]f</div>", 41 expectedSelectedString: "bcde", 42 }, 43 { 44 html: "<ul><li>a[b]c</li></ul>", 45 expectedSelectedString: "b", 46 }, 47 { 48 html: "<ul><li>a[bc</li><li>de]f</li></ul>", 49 expectedSelectedString: "bcde", 50 }, 51 { 52 html: "<div>a[bc</div>" + 53 "<ul><li>de]f</li></ul>", 54 expectedSelectedString: "bcde", 55 }, 56 { 57 html: "<ul><li>a[bc</li></ul>" + 58 "<ul><li>de]f</li></ul>", 59 expectedSelectedString: "bcde", 60 }, 61 { 62 html: "<ul><li>abc</li><li>d[ef</li></ul>" + 63 "<ul><li>gh]i</li></ul>", 64 expectedSelectedString: "efgh", 65 }, 66 { 67 html: "<ul><li>abc</li><li>d[ef</li></ul>" + 68 "<ul><li>gh]i</li><li>jkl</li></ul>", 69 expectedSelectedString: "efgh", 70 }, 71 { 72 html: "<ul><ul><li>a[bc</li></ul><li>de]f</li></ul>", 73 expectedSelectedString: "bcde", 74 }, 75 { 76 html: "<ol><ul><li>a[bc</li></ul><li>de]f</li></ol>", 77 expectedSelectedString: "bcde", 78 }, 79 { 80 html: "<ul><li>a[bc</li><ul><li>de]f</li></ul></ul>", 81 expectedSelectedString: "bcde", 82 }, 83 { 84 html: "<ol><li>a[bc</li><ul><li>de]f</li></ul></ol>", 85 expectedSelectedString: "bcde", 86 }, 87 ]; 88 89 for (const t of tests) { 90 test(() => { 91 utils.setupEditingHost(t.html); 92 document.execCommand("indent"); 93 assert_equals( 94 getSelection().toString().replace(/[ \n\r]+/g, ""), 95 t.expectedSelectedString, 96 `Result: ${editor.innerHTML}` 97 ); 98 }, `Preserve selection after indent at ${t.html}`); 99 } 100 101 </script> 102 </body> 103 </html>