modify.tentative.html (1887B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Selection#modify bidi tests</title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 7 <div id="container"> 8 <div title="LTR text">Hello World</div> 9 <div title="RTL text">مرحبا عالم</div> 10 <div title="RTL+LTR text">مرحبا عالم Hello World</div> 11 <div title="LTR+RTL text">Hello World مرحبا عالم</div> 12 <div title="LTR+RTL+LTR text">Hello World مرحبا عالم Hello World</div> 13 <div title="RTL+LTR+RTL text">مرحبا عالم Hello World مرحبا عالم</div> 14 </div> 15 16 <script> 17 /** 18 * @param {"ltr" | "rtl"} bidi 19 * @param {"left" | "right"} direction 20 * @param {number} length 21 */ 22 function getExpectedOffset(bidi, direction, length) { 23 const isLtr = bidi === "ltr"; 24 const toLeft = direction === "left"; 25 return isLtr === toLeft ? 0 : length; 26 } 27 28 function runTest(div, direction, bidi, postfix = "") { 29 test(() => { 30 div.dir = bidi; 31 32 selection.collapse(div); 33 selection.modify("extend", direction, "lineboundary"); 34 35 const offset = getExpectedOffset( 36 bidi, direction, 37 div.childNodes[0].textContent.length 38 ); 39 40 assert_equals(selection.focusOffset, offset); 41 }, `${div.title} with ${direction} direction in ${bidi} context${postfix}`); 42 } 43 44 const selection = getSelection(); 45 for (const bidi of ["ltr", "rtl"]) { 46 for (const direction of ["left", "right"]) { 47 for (const div of container.children) { 48 runTest(div, direction, bidi) 49 } 50 } 51 } 52 53 // Gecko treats morphed LTR contexts differently from native LTR context 54 // @see https://searchfox.org/mozilla-central/rev/35d927df97900a57ecb562ad13909e392440b0fb/dom/base/Document.h#981-987 55 for (const direction of ["left", "right"]) { 56 for (const div of container.children) { 57 runTest(div, direction, "ltr", " (which was previously rtl)") 58 } 59 } 60 </script>