justify-preserving-selection.tentative.html (4392B)
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&command=justifyCenter"> 7 <meta name="variant" content="?styleWithCSS=false&command=justifyFull"> 8 <meta name="variant" content="?styleWithCSS=false&command=justifyLeft"> 9 <meta name="variant" content="?styleWithCSS=false&command=justifyRight"> 10 <meta name="variant" content="?styleWithCSS=true&command=justifyCenter"> 11 <meta name="variant" content="?styleWithCSS=true&command=justifyFull"> 12 <meta name="variant" content="?styleWithCSS=true&command=justifyLeft"> 13 <meta name="variant" content="?styleWithCSS=true&command=justifyRight"> 14 <title>Test preserving selection after justifying selected content</title> 15 <script src="/resources/testharness.js"></script> 16 <script src="/resources/testharnessreport.js"></script> 17 <script src="/resources/testdriver.js"></script> 18 <script src="/resources/testdriver-vendor.js"></script> 19 <script src="/resources/testdriver-actions.js"></script> 20 <script src="../include/editor-test-utils.js"></script> 21 </head> 22 <body> 23 <div contenteditable></div> 24 <script> 25 "use strict"; 26 27 const editor = document.querySelector("div[contenteditable]"); 28 const utils = new EditorTestUtils(editor); 29 const searchParams = new URLSearchParams(document.location.search); 30 const styleWithCSS = searchParams.get("styleWithCSS"); 31 const command = searchParams.get("command"); 32 document.execCommand("styleWithCSS", false, styleWithCSS); 33 34 // Note that it's not scope of this test how browsers to align the selected 35 // content. 36 37 // html: Initial HTML which will be set editor.innerHTML, it should contain 38 // selection range with a pair of "[" or "{" and "]" or "}". 39 // expectedSelectedString: After executing "outdent", compared with 40 // getSelection().toString().replace(/[ \n\r\t]+/g, "") 41 const tests = [ 42 { 43 html: "<div>a[b]c</div>", 44 expectedSelectedString: "b", 45 }, 46 { 47 html: "<address>a[b]c</address>", // <address> cannot have align attribute 48 expectedSelectedString: "b", 49 }, 50 { 51 html: "<div>a[bc</div>" + 52 "<div>de]f</div>", 53 expectedSelectedString: "bcde", 54 }, 55 { 56 html: "<div>a[bc</div>" + 57 "<address>de]f</address>", 58 expectedSelectedString: "bcde", 59 }, 60 { 61 html: "<address>a[bc</address>" + 62 "<div>de]f</div>", 63 expectedSelectedString: "bcde", 64 }, 65 { 66 html: "<address>a[bc</address>" + 67 "<address>de]f</address>", 68 expectedSelectedString: "bcde", 69 }, 70 { 71 html: "<ul><li>a[b]c</li></ul>", 72 expectedSelectedString: "b", 73 }, 74 { 75 html: "<ul><li>a[bc</li><li>de]f</li></ul>", 76 expectedSelectedString: "bcde", 77 }, 78 { 79 html: "<ul><li>a[bc</li><li>de]f</li><li>ghi</li></ul>", 80 expectedSelectedString: "bcde", 81 }, 82 { 83 html: "<ul><li>abc</li><li>d[ef</li><li>gh]i</li></ul>", 84 expectedSelectedString: "efgh", 85 }, 86 { 87 html: "<ul><li>abc</li><li>d[e]f</li><li>ghi</li></ul>", 88 expectedSelectedString: "e", 89 }, 90 { 91 html: "<ul><li>a[bc</li></ul>" + 92 "<div>de]f</div>", 93 expectedSelectedString: "bcde", 94 }, 95 { 96 html: "<ul><li>abc</li><li>d[ef</li></ul>" + 97 "<div>gh]i</div>", 98 expectedSelectedString: "efgh", 99 }, 100 { 101 html: "<div>a[bc</div>" + 102 "<ul><li>de]f</li></ul>", 103 expectedSelectedString: "bcde", 104 }, 105 { 106 html: "<div>a[bc</div>" + 107 "<ul><li>de]f</li><li>ghi</li></ul>", 108 expectedSelectedString: "bcde", 109 }, 110 { 111 html: "<table><tr><td>a[b]c</td></tr></table>", 112 expectedSelectedString: "b", 113 }, 114 { 115 html: "<table><tr><td>a[bc</td><td>de]f</td></tr></table>", 116 expectedSelectedString: "bcde", 117 }, 118 { 119 html: "<table><tr><td>a[bc</td></tr><tr><td>de]f</td></tr></table>", 120 expectedSelectedString: "bcde", 121 }, 122 { 123 html: "<div>a[bc</div>" + 124 "<table><tr><td>de]f</td></tr></table>", 125 expectedSelectedString: "bcde", 126 }, 127 { 128 html: "<table><tr><td>a[bc</td></tr></table>" + 129 "<div>de]f</div>", 130 expectedSelectedString: "bcde", 131 }, 132 ]; 133 134 for (const t of tests) { 135 test(() => { 136 utils.setupEditingHost(t.html); 137 document.execCommand(command); 138 assert_equals( 139 getSelection().toString().replace(/[ \n\r\t]+/g, ""), 140 t.expectedSelectedString, 141 `Result: ${editor.innerHTML}` 142 ); 143 }, `Preserve selection after ${command} at ${t.html}`); 144 } 145 146 </script> 147 </body> 148 </html>