tor-browser

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

test_bug454326.html (4520B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=454326
      5 -->
      6 <head>
      7  <title>Test for Bug 454326</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=454326">Mozilla Bug 454326</a>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15 </div>
     16 
     17 <div id="partial-text-selection">Hello Hello <div></div>World!</div>
     18 <div id="partial-element-selection"><div id="begin">Hello Hello </div><div></div><div id="end">World!</div></div>
     19 <pre id="test">
     20 <script class="testbody" type="text/javascript">
     21 
     22 /** Test for Bug 454326 */
     23 
     24  function reinitPartialTextSelection() {
     25    var pts = document.getElementById("partial-text-selection");
     26    pts.textContent = null;
     27    pts.appendChild(document.createTextNode("Hello Hello "));
     28    pts.appendChild(document.createElement("div"));
     29    pts.appendChild(document.createTextNode("World!"));
     30  }
     31 
     32 
     33  function doTest() {
     34    var pts = document.getElementById("partial-text-selection");
     35    var ex = null;
     36    try {
     37      var r1 = document.createRange();
     38      r1.setStart(pts.firstChild, 6);
     39      r1.setEnd(pts.lastChild, 6);
     40      is(r1.toString(), "Hello World!", "Wrong range!");
     41      r1.surroundContents(document.createElement("div"));
     42      is(r1.toString(), "Hello World!", "Wrong range!");
     43    } catch(e) {
     44      ex = e;
     45    }
     46    is(ex, null, "Unexpected exception!");
     47 
     48    reinitPartialTextSelection();
     49    ex = null;
     50    try {
     51      var r2 = document.createRange();
     52      r2.setStart(pts.firstChild, 6);
     53      r2.setEnd(pts, 2);
     54      is(r2.toString(), "Hello ", "Wrong range!");
     55      r2.surroundContents(document.createElement("div"));
     56      is(r2.toString(), "Hello ", "Wrong range!");
     57    } catch(e) {
     58      ex = e;
     59    }
     60    is(ex, null, "Unexpected exception!");
     61 
     62    reinitPartialTextSelection();
     63    ex = null;
     64    try {
     65      var r3 = document.createRange();
     66      r3.setStart(pts, 1);
     67      r3.setEnd(pts.lastChild, 6);
     68      is(r3.toString(), "World!", "Wrong range!");
     69      r3.surroundContents(document.createElement("div"));
     70      is(r3.toString(), "World!", "Wrong range!");
     71    } catch(e) {
     72      ex = e;
     73    }
     74    is(ex, null, "Unexpected exception!");
     75 
     76    reinitPartialTextSelection();
     77    ex = null;
     78    try {
     79      var r3 = document.createRange();
     80      r3.setStart(pts.firstChild, 6);
     81      r3.setEnd(pts.firstChild.nextSibling, 0);
     82      is(r3.toString(), "Hello ", "Wrong range!");
     83      r3.surroundContents(document.createElement("div"));
     84      is(r3.toString(), "Hello ", "Wrong range!");
     85    } catch(e) {
     86      ex = e;
     87      is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
     88      is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
     89      is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
     90    }
     91    ok(ex, "There should have been an exception!");
     92 
     93    reinitPartialTextSelection();
     94    ex = null;
     95    try {
     96      var r3 = document.createRange();
     97      r3.setStart(pts.firstChild.nextSibling, 0);
     98      r3.setEnd(pts.lastChild, 6);
     99      is(r3.toString(), "World!", "Wrong range!");
    100      r3.surroundContents(document.createElement("div"));
    101      is(r3.toString(), "World!", "Wrong range!");
    102    } catch(e) {
    103      ex = e;
    104      is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
    105      is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
    106      is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
    107    }
    108    ok(ex, "There should have been an exception!");
    109 
    110    ex = null;
    111    try {
    112      var pes = document.getElementById("partial-element-selection");
    113      var r4 = document.createRange();
    114      r4.setStart(pes.firstChild.firstChild, 6);
    115      r4.setEnd(pes.lastChild.firstChild, 6);
    116      is(r4.toString(), "Hello World!", "Wrong range!");
    117      r4.surroundContents(document.createElement("div"));
    118      is(r4.toString(), "Hello World!", "Wrong range!");
    119    } catch(e) {
    120      ex = e;
    121      is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
    122      is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
    123      is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
    124    }
    125    ok(ex, "There should have been an exception!");
    126  }
    127 
    128  SimpleTest.waitForExplicitFinish();
    129  addLoadEvent(doTest);
    130  addLoadEvent(SimpleTest.finish);
    131 </script>
    132 </pre>
    133 </body>
    134 </html>