tor-browser

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

Range_selectNode.html (15409B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>focus move tests caused by a call of Range.selectNode() and Range.selectNodeContents()</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <body>
      7 <div style="height: 3000px;">Spacer to check whether or not page was scrolled down to focused editor</div>
      8 <p id="staticBefore">static text</p>
      9 <div id="editor" contenteditable><p>content of editor</p></div>
     10 <div id="outerEditor" contenteditable
     11 ><p>content of outer editor</p><div id="staticInEditor" contenteditable="false"
     12 ><p>static content of outer editor</p><div id="innerEditor" contenteditable
     13 ><p>content of inner editor</p></div></div></div>
     14 <p id="staticAfter">static text</p>
     15 <p><a id="anchor" href="about:blank">anchor</a></p>
     16 <script>
     17 "use strict";
     18 
     19 var staticBefore = {
     20    element: document.getElementById("staticBefore"),
     21    textNode: document.getElementById("staticBefore").firstChild,
     22    textLength: document.getElementById("staticBefore").firstChild.length
     23 };
     24 var editor = {
     25    element: document.getElementById("editor"),
     26    textNode: document.getElementById("editor").firstChild.firstChild,
     27    textLength: document.getElementById("editor").firstChild.firstChild.length
     28 };
     29 var outerEditor = {
     30    element: document.getElementById("outerEditor"),
     31    textNode: document.getElementById("outerEditor").firstChild.firstChild,
     32    textLength: document.getElementById("outerEditor").firstChild.firstChild.length
     33 };
     34 var staticInEditor = {
     35    element: document.getElementById("staticInEditor"),
     36    textNode: document.getElementById("staticInEditor").firstChild,
     37    textLength: document.getElementById("staticInEditor").firstChild.length
     38 };
     39 var innerEditor = {
     40    element: document.getElementById("innerEditor"),
     41    textNode: document.getElementById("innerEditor").firstChild.firstChild,
     42    textLength: document.getElementById("innerEditor").firstChild.firstChild.length
     43 };
     44 var staticAfter = {
     45    element: document.getElementById("staticAfter"),
     46    textNode: document.getElementById("staticAfter").firstChild,
     47    textLength: document.getElementById("staticAfter").firstChild.length
     48 };
     49 var anchor = {
     50    element: document.getElementById("anchor"),
     51    textNode: document.getElementById("anchor").firstChild,
     52    textLength: document.getElementById("anchor").firstChild.length
     53 };
     54 
     55 function resetFocusAndSelectionRange(aFocus)
     56 {
     57    document.getSelection().removeAllRanges();
     58    if (document.activeElement) {
     59        document.activeElement.blur();
     60    }
     61    if (aFocus) {
     62        aFocus.element.focus();
     63        document.getSelection().collapse(aFocus.textNode, 0);
     64    } else {
     65        document.getSelection().collapse(staticBefore.textNode, 0);
     66    }
     67    document.documentElement.scrollTop = 0;
     68 }
     69 
     70 function selectNode(aNodeToSelect)
     71 {
     72    document.getSelection().getRangeAt(0).selectNode(aNodeToSelect);
     73 }
     74 
     75 function selectNodeContents(aNodeToSelectItsContents)
     76 {
     77    document.getSelection().getRangeAt(0).selectNodeContents(aNodeToSelectItsContents);
     78 }
     79 
     80 [{ func: selectNode, doingDescription: "Range.selectNode()" },
     81 { func: selectNodeContents, doingDescription: "Range.selectNodeContents()" }].forEach((aTest, aIndex, aArray)=>{
     82    test(function() {
     83        resetFocusAndSelectionRange();
     84        aTest.func(staticBefore.textNode);
     85        assert_equals(document.activeElement, document.body);
     86        assert_equals(document.documentElement.scrollTop, 0);
     87    }, "Active element should be the <body> after " + aTest.doingDescription + " with the first text node of 'staticBefore' when active element is the <body>");
     88    test(function() {
     89        resetFocusAndSelectionRange();
     90        aTest.func(editor.textNode);
     91        assert_equals(document.activeElement, editor.element);
     92        assert_equals(document.documentElement.scrollTop, 0);
     93    }, "Active element should be 'editor' after " + aTest.doingDescription + " with the first text node of 'editor' when active element is the <body>");
     94    test(function() {
     95        resetFocusAndSelectionRange();
     96        aTest.func(outerEditor.textNode);
     97        assert_equals(document.activeElement, outerEditor.element);
     98        assert_equals(document.documentElement.scrollTop, 0);
     99    }, "Active element should be 'outerEditor' after " + aTest.doingDescription + " with the first text node of 'outerEditor' when active element is the <body>");
    100    test(function() {
    101        resetFocusAndSelectionRange();
    102        aTest.func(staticInEditor.textNode);
    103        assert_equals(document.activeElement, document.body);
    104        assert_equals(document.documentElement.scrollTop, 0);
    105    }, "Active element should be the <body> after " + aTest.doingDescription + " with the first text node of 'staticInEditor' when active element is the <body>");
    106    test(function() {
    107        resetFocusAndSelectionRange();
    108        aTest.func(innerEditor.textNode);
    109        assert_equals(document.activeElement, innerEditor.element);
    110        assert_equals(document.documentElement.scrollTop, 0);
    111    }, "Active element should be 'innerEditor' after " + aTest.doingDescription + " with the first text node of 'innerEditor' when active element is the <body>");
    112    test(function() {
    113        resetFocusAndSelectionRange();
    114        aTest.func(anchor.textNode);
    115        assert_equals(document.activeElement, document.body);
    116        assert_equals(document.documentElement.scrollTop, 0);
    117    }, "Active element should be the <body> after " + aTest.doingDescription + " with the first text node of 'anchor' when active element is the <body>");
    118 
    119    test(function() {
    120        resetFocusAndSelectionRange(editor);
    121        aTest.func(staticBefore.textNode);
    122        assert_equals(document.activeElement, editor.element);
    123        assert_equals(document.documentElement.scrollTop, 0);
    124    }, "Active element should be 'editor' after " + aTest.doingDescription + " with the first text node of 'staticBefore' when active element is 'editor'");
    125    test(function() {
    126        resetFocusAndSelectionRange(editor);
    127        aTest.func(editor.textNode);
    128        assert_equals(document.activeElement, editor.element);
    129        assert_equals(document.documentElement.scrollTop, 0);
    130    }, "Active element should be 'editor' after " + aTest.doingDescription + " with the first text node of 'editor' when active element is 'editor'");
    131    test(function() {
    132        resetFocusAndSelectionRange(editor);
    133        aTest.func(outerEditor.textNode);
    134        assert_equals(document.activeElement, outerEditor.element);
    135        assert_equals(document.documentElement.scrollTop, 0);
    136    }, "Active element should be 'outerEditor' after " + aTest.doingDescription + " with the first text node of 'outerEditor' when active element is 'editor'");
    137    test(function() {
    138        resetFocusAndSelectionRange(editor);
    139        aTest.func(staticInEditor.textNode);
    140        assert_equals(document.activeElement, editor.element);
    141        assert_equals(document.documentElement.scrollTop, 0);
    142    }, "Active element should be 'editor' after " + aTest.doingDescription + " with the first text node of 'staticInEditor' when active element is 'editor'");
    143    test(function() {
    144        resetFocusAndSelectionRange(editor);
    145        aTest.func(innerEditor.textNode);
    146        assert_equals(document.activeElement, innerEditor.element);
    147        assert_equals(document.documentElement.scrollTop, 0);
    148    }, "Active element should be 'innerEditor' after " + aTest.doingDescription + " with the first text node of 'innerEditor' when active element is 'editor'");
    149    test(function() {
    150        resetFocusAndSelectionRange(editor);
    151        aTest.func(anchor.textNode);
    152        assert_equals(document.activeElement, editor.element);
    153        assert_equals(document.documentElement.scrollTop, 0);
    154    }, "Active element should be 'editor' after " + aTest.doingDescription + " with the first text node of 'anchor' when active element is the 'editor'");
    155 
    156    test(function() {
    157        resetFocusAndSelectionRange(outerEditor);
    158        aTest.func(staticBefore.textNode);
    159        assert_equals(document.activeElement, outerEditor.element);
    160        assert_equals(document.documentElement.scrollTop, 0);
    161    }, "Active element should be 'outerEditor' after " + aTest.doingDescription + " with the first text node of 'staticBefore' when active element is 'outerEditor'");
    162    test(function() {
    163        resetFocusAndSelectionRange(outerEditor);
    164        aTest.func(editor.textNode);
    165        assert_equals(document.activeElement, editor.element);
    166        assert_equals(document.documentElement.scrollTop, 0);
    167    }, "Active element should be 'editor' after " + aTest.doingDescription + " with the first text node of 'editor' when active element is 'outerEditor'");
    168    test(function() {
    169        resetFocusAndSelectionRange(outerEditor);
    170        aTest.func(outerEditor.textNode);
    171        assert_equals(document.activeElement, outerEditor.element);
    172        assert_equals(document.documentElement.scrollTop, 0);
    173    }, "Active element should be 'outerEditor' after " + aTest.doingDescription + " with the first text node of 'outerEditor' when active element is 'outerEditor'");
    174    test(function() {
    175        resetFocusAndSelectionRange(outerEditor);
    176        aTest.func(staticInEditor.textNode);
    177        assert_equals(document.activeElement, outerEditor.element);
    178        assert_equals(document.documentElement.scrollTop, 0);
    179    }, "Active element should be 'outerEditor' after " + aTest.doingDescription + " with the first text node of 'staticInEditor' when active element is 'outerEditor'");
    180    test(function() {
    181        resetFocusAndSelectionRange(outerEditor);
    182        aTest.func(innerEditor.textNode);
    183        assert_equals(document.activeElement, innerEditor.element);
    184        assert_equals(document.documentElement.scrollTop, 0);
    185    }, "Active element should be 'innerEditor' after " + aTest.doingDescription + " with the first text node of 'innerEditor' when active element is 'outerEditor'");
    186    test(function() {
    187        resetFocusAndSelectionRange(outerEditor);
    188        aTest.func(anchor.textNode);
    189        assert_equals(document.activeElement, outerEditor.element);
    190        assert_equals(document.documentElement.scrollTop, 0);
    191    }, "Active element should be 'outerEditor' after " + aTest.doingDescription + " with the first text node of 'anchor' when active element is the 'outerEditor'");
    192 
    193    test(function() {
    194        resetFocusAndSelectionRange(innerEditor);
    195        aTest.func(staticBefore.textNode);
    196        assert_equals(document.activeElement, innerEditor.element);
    197        assert_equals(document.documentElement.scrollTop, 0);
    198    }, "Active element should be 'innerEditor' after " + aTest.doingDescription + " with the first text node of 'staticBefore' when active element is 'innerEditor'");
    199    test(function() {
    200        resetFocusAndSelectionRange(innerEditor);
    201        aTest.func(editor.textNode);
    202        assert_equals(document.activeElement, editor.element);
    203        assert_equals(document.documentElement.scrollTop, 0);
    204    }, "Active element should be 'editor' after " + aTest.doingDescription + " with the first text node of 'editor' when active element is 'innerEditor'");
    205    test(function() {
    206        resetFocusAndSelectionRange(innerEditor);
    207        aTest.func(outerEditor.textNode);
    208        assert_equals(document.activeElement, outerEditor.element);
    209        assert_equals(document.documentElement.scrollTop, 0);
    210    }, "Active element should be 'outerEditor' after " + aTest.doingDescription + " with the first text node of 'outerEditor' when active element is 'innerEditor'");
    211    test(function() {
    212        resetFocusAndSelectionRange(innerEditor);
    213        aTest.func(staticInEditor.textNode);
    214        assert_equals(document.activeElement, innerEditor.element);
    215        assert_equals(document.documentElement.scrollTop, 0);
    216    }, "Active element should be 'innerEditor' after " + aTest.doingDescription + " with the first text node of 'staticInEditor' when active element is 'innerEditor'");
    217    test(function() {
    218        resetFocusAndSelectionRange(innerEditor);
    219        aTest.func(innerEditor.textNode);
    220        assert_equals(document.activeElement, innerEditor.element);
    221        assert_equals(document.documentElement.scrollTop, 0);
    222    }, "Active element should be 'innerEditor' after " + aTest.doingDescription + " with the first text node of 'innerEditor' when active element is 'innerEditor'");
    223    test(function() {
    224        resetFocusAndSelectionRange(innerEditor);
    225        aTest.func(anchor.textNode);
    226        assert_equals(document.activeElement, innerEditor.element);
    227        assert_equals(document.documentElement.scrollTop, 0);
    228    }, "Active element should be 'innerEditor' after " + aTest.doingDescription + " with the first text node of 'anchor' when active element is the 'innerEditor'");
    229 
    230    test(function() {
    231        resetFocusAndSelectionRange(anchor);
    232        aTest.func(staticBefore.textNode);
    233        assert_equals(document.activeElement, anchor.element);
    234        assert_equals(document.documentElement.scrollTop, 0);
    235    }, "Active element should be 'anchor' after " + aTest.doingDescription + " with the first text node of 'staticBefore' when active element is 'anchor'");
    236    test(function() {
    237        resetFocusAndSelectionRange(anchor);
    238        aTest.func(editor.textNode);
    239        assert_equals(document.activeElement, editor.element);
    240        assert_equals(document.documentElement.scrollTop, 0);
    241    }, "Active element should be 'editor' after " + aTest.doingDescription + " with the first text node of 'editor' when active element is 'anchor'");
    242    test(function() {
    243        resetFocusAndSelectionRange(anchor);
    244        aTest.func(outerEditor.textNode);
    245        assert_equals(document.activeElement, outerEditor.element);
    246        assert_equals(document.documentElement.scrollTop, 0);
    247    }, "Active element should be 'outerEditor' after " + aTest.doingDescription + " with the first text node of 'outerEditor' when active element is 'anchor'");
    248    test(function() {
    249        resetFocusAndSelectionRange(anchor);
    250        aTest.func(staticInEditor.textNode);
    251        assert_equals(document.activeElement, anchor.element);
    252        assert_equals(document.documentElement.scrollTop, 0);
    253    }, "Active element should be 'anchor' after " + aTest.doingDescription + " with the first text node of 'staticInEditor' when active element is 'anchor'");
    254    test(function() {
    255        resetFocusAndSelectionRange(anchor);
    256        aTest.func(innerEditor.textNode);
    257        assert_equals(document.activeElement, innerEditor.element);
    258        assert_equals(document.documentElement.scrollTop, 0);
    259    }, "Active element should be 'innerEditor' after " + aTest.doingDescription + " with the first text node of 'innerEditor' when active element is 'anchor'");
    260    test(function() {
    261        resetFocusAndSelectionRange(anchor);
    262        aTest.func(anchor.textNode);
    263        assert_equals(document.activeElement, anchor.element);
    264        assert_equals(document.documentElement.scrollTop, 0);
    265    }, "Active element should be 'anchor' after " + aTest.doingDescription + " with the first text node of 'anchor' when active element is the 'anchor'");
    266 });
    267 </script>