tor-browser

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

Document-open.html (1300B)


      1 <!doctype html>
      2 <title>Selection Document.open() tests</title>
      3 <div id=log></div>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <script>
      7 "use strict";
      8 
      9 const iframe = document.createElement("iframe");
     10 async_test(t => {
     11  iframe.onload = t.step_func_done(() => {
     12    const originalSelection = iframe.contentWindow.getSelection();
     13    assert_equals(originalSelection.rangeCount, 0, "rangeCount must initially be 0");
     14    iframe.contentDocument.body.appendChild(iframe.contentDocument.createTextNode("foo"));
     15    const range = iframe.contentDocument.createRange();
     16    range.selectNodeContents(iframe.contentDocument.body);
     17    iframe.contentWindow.getSelection().addRange(range);
     18    assert_equals(originalSelection.rangeCount, 1, "rangeCount must be 1 after adding a range");
     19 
     20    iframe.contentDocument.open();
     21 
     22    assert_equals(iframe.contentWindow.getSelection(), originalSelection, "After document.open(), the Selection object must be the same");
     23    assert_equals(iframe.contentWindow.getSelection().rangeCount, 1, "After document.open(), rangeCount must still be 1");
     24    document.body.removeChild(iframe);
     25  });
     26  document.body.appendChild(iframe);
     27 }, "Selection must not be replaced with a new object after document.open()");
     28 </script>