tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

selection-modify-extend-word-generated-content.html (1833B)


      1 <!doctype html>
      2 <html>
      3 <meta charset="utf-8">
      4 <title>Generated content should not connect the first/last word with adjacent line's last/first word</title>
      5 <script src=/resources/testharness.js></script>
      6 <script src=/resources/testharnessreport.js></script>
      7 <style>
      8 p {
      9  white-space: nowrap;
     10 }
     11 p#middleLine::before, p#middleLine::after {
     12  content: "GeneratedText";
     13 }
     14 </style>
     15 <script>
     16 "use strict";
     17 
     18 addEventListener("load", () => {
     19  const middleLine = document.getElementById("middleLine");
     20  test(() => {
     21    getSelection().collapse(middleLine.firstChild, "mid".length);
     22    getSelection().modify("extend", "backward", "word");
     23    assert_in_array(
     24      getSelection().getRangeAt(0).startContainer,
     25      [middleLine, middleLine.firstChild],
     26      "The start container should be in the middle line"
     27    );
     28    assert_equals(
     29      getSelection().getRangeAt(0).startOffset,
     30      0,
     31      "The start offset should be 0"
     32    );
     33  }, "extending selection from middle of first word of the middle line shouldn't extend the range to the previous line");
     34  test(() => {
     35    getSelection().collapse(middleLine.firstChild, "middle li".length);
     36    getSelection().modify("extend", "forward", "word");
     37    assert_in_array(
     38      getSelection().getRangeAt(0).endContainer,
     39      [middleLine, middleLine.firstChild],
     40      "The end container should be in the middle line"
     41    );
     42    assert_equals(
     43      getSelection().getRangeAt(0).endOffset,
     44      getSelection().getRangeAt(0).endContainer.length,
     45      "The end offset should be the length of the container"
     46    );
     47  }, "extending selection from middle of last word of the middle line shouldn't extend the range to the next line");
     48 }, {once: true});
     49 </script>
     50 <body>
     51 <p id="previousLine">previous line</p>
     52 <p id="middleLine">middle line</p>
     53 <p id="nextLine">last line</p>
     54 </body>
     55 </html>