tor-browser

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

selection-range-after-editinghost-removed.html (2925B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>Selection range in an editing host after the host is removed</title>
      6 <script src=/resources/testharness.js></script>
      7 <script src=/resources/testharnessreport.js></script>
      8 <script>
      9 "use strict";
     10 
     11 addEventListener("load", () => {
     12  const container = document.querySelector("div");
     13  test(() => {
     14    const editingHost = document.createElement("div");
     15    editingHost.contentEditable = true;
     16    editingHost.innerHTML = "ABC<br>";
     17    container.appendChild(editingHost);
     18    editingHost.focus();
     19    getSelection().collapse(editingHost, 0);
     20    editingHost.remove();
     21    assert_equals(getSelection().focusNode, container, "focusNode should be the container");
     22    assert_equals(getSelection().focusOffset, 0, "focusOffset should be 0");
     23  }, "Selection range in an editing host should be collapsed where the host was after it's removed");
     24 
     25  test(() => {
     26    const wrapper = document.createElement("div");
     27    wrapper.id = "wrapper";
     28    const editingHost = document.createElement("div");
     29    editingHost.contentEditable = true;
     30    editingHost.innerHTML = "ABC<br>";
     31    wrapper.appendChild(editingHost);
     32    container.appendChild(wrapper);
     33    editingHost.focus();
     34    getSelection().collapse(editingHost, 0);
     35    wrapper.remove();
     36    assert_equals(getSelection().focusNode, container, "focusNode should be the container");
     37    assert_equals(getSelection().focusOffset, 0, "focusOffset should be 0");
     38  }, "Selection range in an editing host should be collapsed where the host was after its parent is removed");
     39 
     40  test(() => {
     41    const editingHost = document.createElement("div");
     42    editingHost.contentEditable = true;
     43    editingHost.innerHTML = "ABC<br>";
     44    container.appendChild(editingHost);
     45    editingHost.focus();
     46    getSelection().collapse(editingHost, 0);
     47    editingHost.replaceWith(editingHost);
     48    assert_equals(getSelection().focusNode, container, "focusNode should be the container");
     49    assert_equals(getSelection().focusOffset, 0, "focusOffset should be 0");
     50    editingHost.remove();
     51  }, "Selection range in an editing host should be collapsed where the host was after it's replaced with itself (.replaceWith)");
     52 
     53  test(() => {
     54    const editingHost = document.createElement("div");
     55    editingHost.contentEditable = true;
     56    editingHost.innerHTML = "ABC<br>";
     57    container.appendChild(editingHost);
     58    editingHost.focus();
     59    getSelection().collapse(editingHost, 0);
     60    container.replaceChild(editingHost, editingHost);
     61    assert_equals(getSelection().focusNode, container, "focusNode should be the container");
     62    assert_equals(getSelection().focusOffset, 0, "focusOffset should be 0");
     63    editingHost.remove();
     64  }, "Selection range in an editing host should be collapsed where the host was after it's replaced with itself (.replaceChild)");
     65 }, {once: true});
     66 </script>
     67 </head>
     68 <body><div id="container"></div></body>
     69 </html>