tor-browser

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

removeRange.html (1897B)


      1 <!DOCTYPE html>
      2 <title>Selection.removeRange tests</title>
      3 <body>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="common.js"></script>
      7 <script>
      8 "use strict";
      9 
     10 testRanges.forEach(function(rangeData, index) {
     11    var endpoints = eval(rangeData);
     12    if (!isSelectableNode(endpoints[0]) || !isSelectableNode(endpoints[2]))
     13        return;
     14    test(function() {
     15        var selection = getSelection();
     16        selection.removeAllRanges();
     17        var range = ownerDocument(endpoints[0]).createRange();
     18        range.setStart(endpoints[0], endpoints[1]);
     19        range.setEnd(endpoints[2], endpoints[3]);
     20 
     21        selection.addRange(range);
     22        assert_equals(selection.rangeCount, 1);
     23        selection.removeRange(range);
     24        assert_equals(selection.rangeCount, 0, 'Range should be correctly removed.');
     25        assert_equals(selection.anchorNode, null);
     26        assert_equals(selection.focusNode, null);
     27 
     28        selection.addRange(range);
     29        assert_equals(selection.rangeCount, 1);
     30        var equivalentRange = ownerDocument(endpoints[0]).createRange();
     31        equivalentRange.setStart(endpoints[0], endpoints[1]);
     32        equivalentRange.setEnd(endpoints[2], endpoints[3]);
     33        assert_throws_dom("NotFoundError",
     34                          function() { selection.removeRange(equivalentRange) },
     35                          "Removing a different range should throw");
     36        assert_equals(selection.rangeCount, 1, 'Equivalent Range should not remove the registered Range.');
     37 
     38    }, 'removeRange() with Range ' + index);
     39 });
     40 
     41 test(function() {
     42    var selection = getSelection();
     43    assert_throws_js(TypeError, function() { selection.removeRange(null); });
     44    assert_throws_js(TypeError, function() { selection.removeRange(selection); });
     45 }, 'removeRange() argument is non-optional Range');
     46 </script>
     47 </body>