tor-browser

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

selection-in-contentEditable-at-turning-designMode-on-off.tentative.html (1753B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>selection in contenteditable should not be changed when designMode is turned on/off</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <div id="log"></div>
      7 <iframe srcdoc="<body contenteditable>abc</body>"></iframe>
      8 <script>
      9  const test_load = async_test("Selection in contenteditable shouldn't be reinitialized when changing designMode");
     10  window.addEventListener("load", test_load.step_func_done(() => {
     11    let iframe = document.querySelector("iframe");
     12    let iframeSelection = iframe.contentDocument.getSelection();
     13    iframe.focus();
     14    iframeSelection.collapse(iframe.contentDocument.body, 1);
     15    function summariseRange(range) {
     16      if (!range) {
     17        return "null";
     18      }
     19      return `(${range.startContainer.nodeName}, ${range.startOffset}) - (${range.endContainer.nodeName}, ${range.endOffset})`;
     20    }
     21    let maybeNormalizedRangeSummary = summariseRange(iframeSelection.getRangeAt(0));
     22    assert_in_array(maybeNormalizedRangeSummary, ["(BODY, 1) - (BODY, 1)", "(#text, 3) - (#text, 3)"],
     23                    "Selection collapsed at end of <body> can be either as-is or normalized to the end of the text node");
     24    iframe.contentDocument.designMode = "on";
     25    assert_equals(summariseRange(iframeSelection.getRangeAt(0)), maybeNormalizedRangeSummary,
     26                  "Turning designMode on at load event shouldn't change selection in contenteditable");
     27    iframe.contentDocument.designMode = "off";
     28    assert_equals(summariseRange(iframeSelection.getRangeAt(0)), maybeNormalizedRangeSummary,
     29                  "Turning designMode off at load event shouldn't change selection in contenteditable");
     30  }));
     31 </script>