tor-browser

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

selectAllChildren.html (2647B)


      1 <!doctype html>
      2 <title>Selection.selectAllChildren tests</title>
      3 <meta name="timeout" content="long">
      4 <div id=log></div>
      5 <script src=/resources/testharness.js></script>
      6 <script src=/resources/testharnessreport.js></script>
      7 <script src=common.js></script>
      8 <script>
      9 "use strict";
     10 
     11 testRanges.unshift("[]");
     12 
     13 for (var i = 0; i < testRanges.length; i++) {
     14    var endpoints = eval(testRanges[i]);
     15 
     16    for (var j = 0; j < testNodes.length; j++) {
     17        var node = eval(testNodes[j]);
     18 
     19        test(function() {
     20            setSelectionForwards(endpoints);
     21            var originalRange = getSelection().rangeCount
     22                ? getSelection().getRangeAt(0)
     23                : null;
     24 
     25            if (node.nodeType == Node.DOCUMENT_TYPE_NODE) {
     26                assert_throws_dom("INVALID_NODE_TYPE_ERR", function() {
     27                    selection.selectAllChildren(node);
     28                }, "selectAllChildren() on a DocumentType must throw InvalidNodeTypeError");
     29                return;
     30            }
     31 
     32            selection.selectAllChildren(node);
     33            if (!document.contains(node)) {
     34                if (originalRange) {
     35                    assert_equals(getSelection().getRangeAt(0), originalRange,
     36                        "selectAllChildren must do nothing");
     37                } else {
     38                    assert_equals(getSelection().rangeCount, 0,
     39                        "selectAllChildren must do nothing");
     40                }
     41                return;
     42            }
     43            // This implicitly tests that the selection is forwards, by using
     44            // anchorOffset/focusOffset instead of getRangeAt.
     45            assert_equals(selection.rangeCount, 1,
     46                "After selectAllChildren, rangeCount must be 1");
     47            assert_equals(selection.anchorNode, node,
     48                "After selectAllChildren, anchorNode must be the given node");
     49            assert_equals(selection.anchorOffset, 0,
     50                "After selectAllChildren, anchorOffset must be 0");
     51            assert_equals(selection.focusNode, node,
     52                "After selectAllChildren, focusNode must be the given node");
     53            assert_equals(selection.focusOffset, node.childNodes.length,
     54                "After selectAllChildren, focusOffset must be the given node's number of children");
     55            if (originalRange) {
     56                assert_not_equals(getSelection().getRangeAt(0), originalRange,
     57                    "selectAllChildren must replace any existing range, not mutate it");
     58            }
     59        }, "Range " + i + " " + testRanges[i] + ", node " + j + " " + testNodes[j]);
     60    }
     61 }
     62 
     63 testDiv.style.display = "none";
     64 </script>