tor-browser

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

range-client-rects-surrogate-indexing.html (2423B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Range.getClientRects should correct indexing into trailing surrogates</title>
      4 <link rel="help" href="https://drafts.csswg.org/cssom-view-1/#dom-range-getclientrects">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <div id="surrogates">🌠a🌠</div>
      8 <span id="surrogate">🌠a</span><span id="surrogate2">🌠</span>
      9 <script>
     10  test(function () {
     11    const surrogates = document.getElementById("surrogates");
     12    const surrogate = document.getElementById("surrogate");
     13    const surrogate2 = document.getElementById("surrogate2");
     14 
     15    // test range with one container
     16    fullrange = document.createRange();
     17    fullrange.setStart(surrogates.firstChild, 0);
     18    fullrange.setEnd(surrogates.firstChild, 5);
     19 
     20    range = document.createRange();
     21    range.setStart(surrogates.firstChild, 1);
     22    range.setEnd(surrogates.firstChild, 5);
     23 
     24    assert_equals(range.getClientRects()[0].width, fullrange.getClientRects()[0].width);
     25 
     26    range.setStart(surrogates.firstChild, 0);
     27    range.setEnd(surrogates.firstChild, 4);
     28 
     29    assert_equals(range.getClientRects()[0].width, fullrange.getClientRects()[0].width);
     30 
     31    range.setStart(surrogates.firstChild, 1);
     32    range.setEnd(surrogates.firstChild, 4);
     33 
     34    assert_equals(range.getClientRects()[0].width, fullrange.getClientRects()[0].width);
     35 
     36    // test range with two containers
     37    fullrange.setStart(surrogate.firstChild, 0);
     38    fullrange.setEnd(surrogate2.firstChild, 2);
     39 
     40    range.setStart(surrogate.firstChild, 1);
     41    range.setEnd(surrogate2.firstChild, 2);
     42 
     43    assert_equals(range.getClientRects()[0].width, fullrange.getClientRects()[0].width);
     44    assert_equals(range.getClientRects()[1].width, fullrange.getClientRects()[1].width);
     45 
     46    range.setStart(surrogate.firstChild, 0);
     47    range.setEnd(surrogate2.firstChild, 1);
     48 
     49    assert_equals(range.getClientRects()[0].width, fullrange.getClientRects()[0].width);
     50    assert_equals(range.getClientRects()[1].width, fullrange.getClientRects()[1].width);
     51 
     52    range.setStart(surrogate.firstChild, 1);
     53    range.setEnd(surrogate2.firstChild, 1);
     54 
     55    assert_equals(range.getClientRects()[0].width, fullrange.getClientRects()[0].width);
     56    assert_equals(range.getClientRects()[1].width, fullrange.getClientRects()[1].width);
     57  }, "Range.getClientRects should correct indexing into trailing surrogates")
     58 </script>